Created
July 3, 2013 04:02
-
-
Save uknowho/5915365 to your computer and use it in GitHub Desktop.
A quick way to create an UIImage of a solid color for a specified dimension. You can use this bit of code in an Objective-C category to "extend" UIImage.
This file contains 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 *)imageWithColor:(UIColor *)color andBounds:(CGRect)imgBounds { | |
UIGraphicsBeginImageContextWithOptions(imgBounds.size, NO, 0); | |
[color setFill]; | |
UIRectFill(imgBounds); | |
UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return img; | |
} |
@instamobile, You are proposing totally different thing than the implementation UIImage+withColor.m provides
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's a more elegant solution to this, by loading the image as .alwaysTemplate. Here's a Swift 4 short implementation of how to color an image. Check it out!