Skip to content

Instantly share code, notes, and snippets.

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)
UIRectFill(CGRect(origin:, size: size))
let image = UIGraphicsGetImageFromCurrentImageContext()
return image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment