+ (UIImage *)coloredImage:(UIImage *)image
:(UIColor *)color
{
UIGraphicsBeginImageContext(image.size);CGContextRef context = UIGraphicsGetCurrentContext();[color setFill];CGContextTranslateCTM(context, 0, image.size.height);
CGContextScaleCTM(context, 1.0, -1.0);CGContextSetBlendMode(context, kCGBlendModeColorBurn);
CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
CGContextDrawImage(context, rect, image.CGImage);CGContextClipToMask(context, rect, image.CGImage);
CGContextAddRect(context, rect);
CGContextDrawPath(context, kCGPathFill);UIImage *coloredImage = UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();return coloredImage;
}
:(UIColor *)color
{
UIGraphicsBeginImageContext(image.size);CGContextRef context = UIGraphicsGetCurrentContext();[color setFill];CGContextTranslateCTM(context, 0, image.size.height);
CGContextScaleCTM(context, 1.0, -1.0);CGContextSetBlendMode(context, kCGBlendModeColorBurn);
CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
CGContextDrawImage(context, rect, image.CGImage);CGContextClipToMask(context, rect, image.CGImage);
CGContextAddRect(context, rect);
CGContextDrawPath(context, kCGPathFill);UIImage *coloredImage = UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();return coloredImage;
}
这段代码就是把你的 image 的像素 和 color 的值混合一下