私は既に持っているUIImageにNSStringとボーダーを描画したいと思います。 NSStringをUIImageとして描画するメソッドが見つかりましたが、私が提供するイメージを描画する必要があります。iOS:UIImageでNSStringとボーダーを描画します。
-(UIImage *)imageFromText:(NSString *)text
{
// set the font type and size
UIFont *font = [UIFont systemFontOfSize:20.0];
CGSize size = [text sizeWithFont:font];
// check if UIGraphicsBeginImageContextWithOptions is available (iOS is 4.0+)
if (UIGraphicsBeginImageContextWithOptions != NULL)
UIGraphicsBeginImageContextWithOptions(size,NO,0.0);
else
// iOS is < 4.0
UIGraphicsBeginImageContext(size);
// optional: add a shadow, to avoid clipping the shadow you should make the context size bigger
//
// CGContextRef ctx = UIGraphicsGetCurrentContext();
// CGContextSetShadowWithColor(ctx, CGSizeMake(1.0, 1.0), 5.0, [[UIColor grayColor] CGColor]);
// draw in context, you can use also drawInRect:withFont:
[text drawAtPoint:CGPointMake(0.0, 0.0) withFont:font];
// transfer image
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
ボーダーを追加するだけでなく、自分の背景イメージを提供するためにこの方法を変更するにはどうすればよいですか?
偉大をチェックし、境界線のUIImage
にNSStringのとの境界線を描画する際に、しかし最終的に私はUIImageを置き換えるためにUIButtonを使用し、それ背景Imageを持ち、Label.textを追加することもできます。 – meadlai