이미지에 텍스트 추가하기.
stackoverflow 에서 퍼옴.
- (UIImage*)drawFront:(UIImage*)image text:(NSString*)text atPoint:(CGPoint)point
{
//UIFont *font = [UIFont fontWithName:@"Halter" size:21];
UIGraphicsBeginImageContext(image.size);
[image drawInRect:CGRectMake(0,0,image.size.width,image.size.height)];
CGRect rect = CGRectMake(point.x, (point.y - 5), image.size.width, image.size.height);
[[UIColor whiteColor] set];
NSMutableAttributedString* attString = [[NSMutableAttributedString alloc] initWithString:text];
NSRange range = NSMakeRange(0, [attString length]);
//[attString addAttribute:NSFontAttributeName value:font range:range];
[attString addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:range];
NSShadow* shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor darkGrayColor];
shadow.shadowOffset = CGSizeMake(1.0f, 1.5f);
[attString addAttribute:NSShadowAttributeName value:shadow range:range];
[attString drawInRect:CGRectIntegral(rect)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
'iOS 초보' 카테고리의 다른 글
UITextView 에 html 내용 보여주기 (0) | 2018.11.28 |
---|---|
UIView deep copy (0) | 2018.11.14 |
landscape app. UIImagePickerController 사용하기 (0) | 2016.10.26 |
ios. ssl. client certificate. 클라이언트 인증서. pinning (0) | 2016.10.21 |
GPUImage 사용 (0) | 2016.09.21 |