// // UIImage+ImageWithColor.m // WordClock // // Created by James Rutherford on 2012-12-03. // Copyright (c) 2012 Braxio Interactive. All rights reserved. // #import "UIImage+ImageWithColor.h" @implementation UIImage (ImageWithColor) + (UIImage *)imageNamed:(NSString *)name imageWithColor:(UIColor *)color { UIImage *img = nil; img = [UIImage imageNamed:name]; // lets tint the icon - assumes your icons are black UIGraphicsBeginImageContext(img.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextTranslateCTM(context, 0, img.size.height); CGContextScaleCTM(context, 1.0, -1.0); CGRect rect = CGRectMake(0, 0, img.size.width, img.size.height); // draw alpha-mask CGContextSetBlendMode(context, kCGBlendModeNormal); CGContextDrawImage(context, rect, img.CGImage); // draw tint color, preserving alpha values of original image CGContextSetBlendMode(context, kCGBlendModeSourceIn); [color setFill]; CGContextFillRect(context, rect); UIImage *coloredImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return coloredImage; } @end