Created
September 24, 2010 00:28
-
-
Save willbailey/594664 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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