Last active
December 29, 2015 07:38
-
-
Save sag333ar/7637021 to your computer and use it in GitHub Desktop.
Create an image using color and size supplied in arguments.
This file contains hidden or 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
| // get image color & size as parameters | |
| + (UIImage *)imageWithColor:(UIColor *)color andSize:(CGSize)size | |
| { | |
| UIImage *img = nil; | |
| // create rectangle/square of size supplied | |
| CGRect rect = CGRectMake(0, 0, size.width, size.height); | |
| // create context of size supplied | |
| UIGraphicsBeginImageContext(rect.size); | |
| // get context reference | |
| CGContextRef context = UIGraphicsGetCurrentContext(); | |
| // set fill color | |
| CGContextSetFillColorWithColor(context,color.CGColor); | |
| // fill the color in context | |
| CGContextFillRect(context, rect); | |
| // create image from context | |
| img = UIGraphicsGetImageFromCurrentImageContext(); | |
| // end context | |
| UIGraphicsEndImageContext(); | |
| // return image | |
| return img; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment