Created
May 29, 2021 03:54
-
-
Save anupamchugh/6aefb0fc8043fa7fe584e99e7e8f2e2c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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