Skip to content

Instantly share code, notes, and snippets.

@anupamchugh
Created May 29, 2021 03:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anupamchugh/6aefb0fc8043fa7fe584e99e7e8f2e2c to your computer and use it in GitHub Desktop.
Save anupamchugh/6aefb0fc8043fa7fe584e99e7e8f2e2c to your computer and use it in GitHub Desktop.
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