Skip to content

Instantly share code, notes, and snippets.

@iltercengiz
Last active August 29, 2015 14:08
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save iltercengiz/eb0dabe34463e3509286 to your computer and use it in GitHub Desktop.
Generate 1x1 sized UIImage from UIColor
+ (UIImage *)imageFromColor:(UIColor *)color {
UIImage *image = ({
CGRect rect = CGRectMake(0.0, 0.0, 1.0, 1.0);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, color.CGColor);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
image;
});
return image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment