Skip to content

Instantly share code, notes, and snippets.

@kevinmcmahon
Created April 3, 2012 20:59
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kevinmcmahon/2295471 to your computer and use it in GitHub Desktop.
Save kevinmcmahon/2295471 to your computer and use it in GitHub Desktop.
Create a 1x1 UIImage from a UIColor
- (UIImage *)imageWithColor:(UIColor *)color {
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
@alvareztech
Copy link

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment