UIGraphic

UIGraphic
这里有一篇纯正的分享文章 https://www.jianshu.com/p/494c57f49479

  1. 向图片中添加文字, 类似水印
- (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]];
}

效果:


11524110791_.pic.jpg
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 15,069评论 4 61
  • 写在前面选择一个职业也就选择了一种生活方式当你发自内心热爱它时一切都变得可爱起来了 01 今天是周一,新的一周不知...
    我是不一样的花火阅读 1,345评论 0 1
  • 写下这个题目,似乎非常可笑。八点钟上班,不是很正常吗?我们这样的小城市,又没有朝九晚五的上班必要,可不就应...
    江汉渔歌阅读 311评论 0 0
  • 今天是周一,我选择了调休,着实休息了一天放松、调整一下。最近感觉生活一团糟,没有过成我想要的样子。虽然每天...
    夏树大笨熊阅读 344评论 0 0

友情链接更多精彩内容