Last active
November 18, 2020 02:59
-
-
Save Andy0570/9102beeb1a499e027f0cb614e4da635b to your computer and use it in GitHub Desktop.
通过颜色生成图片
This file contains 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 imageWithColor(color: UIColor) -> UIImage { | |
let rect: CGRect = CGRect(x: 0, y: 0, width: 1, height: 1) | |
UIGraphicsBeginImageContextWithOptions(CGSize(width: 1, height: 1), false, 0) | |
color.setFill() | |
UIRectFill(rect) | |
let image: UIImage? = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() | |
return image! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: