How to change the UIImage Tint Color

Change Tint Color Objective-C


Learn how to change the tint color of an image in whatever color you like with this simple category. I am using this category for more than 3 years, so I can say it’s well tested and never let me down.


Here is the snippet: 

+ (UIImage *)imageNamed:(NSString *)name color:(UIColor *)color
    UIImage *image = [UIImage imageNamed:name];
	CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
	UIGraphicsBeginImageContextWithOptions(rect.size, NO, image.scale);
	CGContextRef c = UIGraphicsGetCurrentContext();
	[image drawInRect:rect];
	CGContextSetFillColorWithColor(c, [color CGColor]);
	CGContextSetBlendMode(c, kCGBlendModeSourceAtop);
	CGContextFillRect(c, rect);
	UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
	return result;


Example usage: 

imgView.image = [UIImage imageNamed:@"img_name" color:[UIColor blueColor]];


Leave a Reply

Your email address will not be published. Required fields are marked *