Skip to content

Instantly share code, notes, and snippets.

@bananita
Created December 16, 2015 19:30
Show Gist options
  • Save bananita/938b7f229e2773d9c9f6 to your computer and use it in GitHub Desktop.
Save bananita/938b7f229e2773d9c9f6 to your computer and use it in GitHub Desktop.
uicolor -> uiimage
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