Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
extension UIImage {
class func imageFromColor(color: UIColor, size: CGSize=CGSize(width: 1, height: 1), scale: CGFloat) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(size, false, scale)
color.setFill()
UIRectFill(CGRect(origin: CGPoint.zero, size: size))
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment