Created
December 16, 2015 19:30
-
-
Save bananita/938b7f229e2773d9c9f6 to your computer and use it in GitHub Desktop.
uicolor -> uiimage
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, 10, 10) | |
UIGraphicsBeginImageContext(rect.size) | |
let context = UIGraphicsGetCurrentContext(); | |
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