Skip to content

Instantly share code, notes, and snippets.

@agiletalk
Created May 13, 2013 08:18
Show Gist options
  • Save agiletalk/5566881 to your computer and use it in GitHub Desktop.
Save agiletalk/5566881 to your computer and use it in GitHub Desktop.
How to change the color of an UIImage
+ (UIImage *)imageNamed:(NSString *)name withColor:(UIColor *)color;
{
UIImage *image = [UIImage imageNamed:name];
CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClipToMask(context, rect, image.CGImage);
CGContextSetFillColorWithColor(context, color.CGColor);
CGContextFillRect(context, rect);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImage *coloredImage = [UIImage imageWithCGImage:img.CGImage scale:1.0 orientation:UIImageOrientationDownMirrored];
return coloredImage;
}
@lukaskubanek
Copy link

Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment