NSString과 테두리를 이미 가지고있는 UIImage에 그려야합니다. 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