Skip to content

Instantly share code, notes, and snippets.

@y8k
Last active August 29, 2015 14:19
Show Gist options
  • Save y8k/55927b714678f66842d3 to your computer and use it in GitHub Desktop.
Save y8k/55927b714678f66842d3 to your computer and use it in GitHub Desktop.
Howto: Get UIImage from UIColor
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