Skip to content

Instantly share code, notes, and snippets.

@willbailey
Created September 24, 2010 00:28
Show Gist options
  • Save willbailey/594664 to your computer and use it in GitHub Desktop.
Save willbailey/594664 to your computer and use it in GitHub Desktop.
- (UIImage*)tintedImageWithColor:(UIColor*)tint {
CGSize size = self.size;
CGRect imageBounds;
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] &&
[[UIScreen mainScreen] scale] == 2) {
imageBounds = CGRectMake(0, 0, size.width * 2, size.height * 2);
} else {
imageBounds = CGRectMake(0, 0, size.width, size.height);
}
UIGraphicsBeginImageContext(imageBounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[self drawInRect:imageBounds blendMode:kCGBlendModeNormal alpha:1.0];
[tint set];
CGContextSetBlendMode(context, kCGBlendModeSourceIn);
CGContextFillRect(context, imageBounds);
UIImage* tintedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return tintedImage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment