Created
May 3, 2014 22:56
-
-
Save baltpeter/c237652d64b4ed1278df to your computer and use it in GitHub Desktop.
Create UIImage rectangle from color
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 { | |
CGRect rect = CGRectMake(0, 0, 1, 1); | |
// Create a 1 by 1 pixel context | |
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0); | |
[color setFill]; | |
UIRectFill(rect); // Fill it with your color | |
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return image; | |
} | |
// source: http://ioscodesnippet.com/2011/08/22/creating-a-placeholder-uiimage-dynamically-with-color/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment