Skip to content

Instantly share code, notes, and snippets.

@baltpeter
Created May 3, 2014 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baltpeter/c237652d64b4ed1278df to your computer and use it in GitHub Desktop.
Save baltpeter/c237652d64b4ed1278df to your computer and use it in GitHub Desktop.
Create UIImage rectangle from color
+ (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