UIGraphic

作者: 霸_霸霸 | 来源:发表于2018-04-19 12:06 被阅读15次

    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

    相关文章

      网友评论

          本文标题:UIGraphic

          本文链接:https://www.haomeiwen.com/subject/knqwkftx.html