UIImage に色と境界線のある描画ストローク テキストを実装しようとしていますが、解決策が得られません。
このTHLabelをテキストのストロークと境界線に使用しましたが、正常に機能しますが、そのコードを描画イメージにコピーした場合にのみ機能するため、その時点で機能します。
同じスクリーンショットを参照してください。助言がありますか?
UIImage メソッドにテキストを描画する:
- (UIImage *) drawText:(NSString*)text
inImage:(UIImage*)image
atPoint:(NSString *)location{
CGFloat fontSize = image.size.width*3/30.0;
NSString *fontName = @"Arial";
int w = image.size.width;
int h = image.size.height;
UIFont *font=[UIFont fontWithName:fontName size:fontSize];
UIGraphicsBeginImageContext(image.size);
[image drawInRect:CGRectMake(0,0,image.size.width,image.size.height)];
int textFrameY = 25;
int textFrameX = 5;
CGSize aSize = [text sizeWithFont:font];
CGRect rect = CGRectMake(textFrameX,textFrameY, 80, 30);
CGSize lSize = [location sizeWithFont:font];
CGRect rect1 = CGRectMake(image.size.width-lSize.width-fontSize-textFrameX, h-(fontSize*3)-textFrameY, w, h);
[[UIColor blackColor] set];
CGContextFillRect(UIGraphicsGetCurrentContext(), rect1);
CGContextFillRect(UIGraphicsGetCurrentContext(), rect);
[[UIColor whiteColor] set];
[text drawInRect:CGRectIntegral(rect) withFont:font];
[location drawInRect:CGRectIntegral(rect1) withFont:font];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;}
ストロークの色とテキスト メソッドの境界線の THLabel コード:
// Demonstrate stroke.
self.label3.strokeColor = kStrokeColor;
self.label3.strokeSize = kStrokeSize;
