UIGraphic
这里有一篇纯正的分享文章 https://www.jianshu.com/p/494c57f49479
- 向图片中添加文字, 类似水印
- (UIImage *)addText:(NSString *)string toImage:(UIImage *)image withTextFontSize:(NSInteger)fontSize fontColor:(UIColor *)fontColor {
UIGraphicsBeginImageContext(image.size);
[image drawAtPoint:CGPointZero];
NSMutableDictionary *attributDic = [NSMutableDictionary dictionary];
attributDic[NSForegroundColorAttributeName] = fontColor;
attributDic[NSFontAttributeName] = [UIFont systemFontOfSize:fontSize];
[string drawAtPoint:CGPointMake(20, 20) withAttributes:attributDic];
UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultImage;
}
调用该方法:
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *picImage = [UIImage imageNamed:@"pic"];
self.logoImageView.image = [self addText:@"Github Peyton" toImage:picImage withTextFontSize:25 fontColor:[UIColor blackColor]];
}
效果: