//改变图片颜色
- (UIImage *)imageWithColor:(UIColor *)color image:(NSString *)image
{
UIGraphicsBeginImageContextWithOptions(self.frame.size, NO,2);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0, self.frame.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextSetBlendMode(context, kCGBlendModeNormal);
CGRect rect = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
//转换 UIImage 的格式
UIImage *loadImage=[UIImage imageNamed:image];
CGImageRef cgimage=loadImage.CGImage;
CGContextClipToMask(context, rect,cgimage);
[color setFill];
CGContextFillRect(context, rect);
UIImage*newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
网友评论