Last active
August 29, 2015 14:19
-
-
Save y8k/55927b714678f66842d3 to your computer and use it in GitHub Desktop.
Howto: Get UIImage from UIColor
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
func imageFromColor(color:UIColor) -> UIImage { | |
let rect = CGRectMake(0.0, 0.0, 1.0, 1.0) | |
UIGraphicsBeginImageContext(rect.size) | |
let context = UIGraphicsGetCurrentContext() as CGContextRef | |
CGContextSetFillColorWithColor(context, color.CGColor) | |
CGContextFillRect(context, rect) | |
let image = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() | |
return image | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment