@implementation UIImage(OverlayColor)
- (UIImage *)imageWithOverlayColor:(UIColor *)color
{
CGRect rect = CGRectMake(0.0f, 0.0f, self.size.width, self.size.height);
if (UIGraphicsBeginImageContextWithOptions) {
CGFloat imageScale = 1.0f;
if ([self respondsToSelector:@selector(scale)])
imageScale = self.scale;
UIGraphicsBeginImageContextWithOptions(self.size, NO, imageScale);
}
else {
UIGraphicsBeginImageContext(self.size);
}
[self drawInRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetBlendMode(context, kCGBlendModeSourceIn);
CGContextSetFillColorWithColor(context, color.CGColor);
CGContextFillRect(context, rect);
UIImage *outImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return outImage;
}
+ (UIImage *)invertImageNamed:(NSString *)name {
UIColor *offWhite = [UIColor colorWithRed:(245.f/255.f)
green:(245.f/255.f)
blue:(245.f/255.f)
alpha:1.f];
// offWhite looks nice on a scroll view background, however,
// a suitable alternative is [UIColor whiteColor]
return [[UIImage imageNamed:name] imageWithOverlayColor:offWhite];
}