改变图片颜色

2018-09-20  本文已影响8人  化二缺

很多时候 美工给的图片 颜色并不合适 或者 急需一个其他颜色的 已有图标 可以用这个方法 改变图标颜色

- (UIImage *)image:(UIImage *)image WithColor:(UIColor *)color
{
    
    UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale);
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextTranslateCTM(context, 0, image.size.height);
    
    CGContextScaleCTM(context, 1.0, -1.0);
    
    CGContextSetBlendMode(context, kCGBlendModeNormal);
    
    CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
    
    CGContextClipToMask(context, rect, image.CGImage);
    
    [color setFill];
    
    CGContextFillRect(context, rect);
    
    UIImage*newImage = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return newImage;
    
}
上一篇 下一篇

猜你喜欢

热点阅读