|
@@ -368,5 +368,16 @@ public extension UIImage {
|
|
|
print("保存图片成功到:filePath=\(outFilePath)")
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ convenience init?(color: UIColor, size: CGSize = CGSize(width: 1, height: 1)) {
|
|
|
+ let rect = CGRect(origin: .zero, size: size)
|
|
|
+ UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0)
|
|
|
+ color.setFill()
|
|
|
+ UIRectFill(rect)
|
|
|
+ let image = UIGraphicsGetImageFromCurrentImageContext()
|
|
|
+ UIGraphicsEndImageContext()
|
|
|
+
|
|
|
+ guard let cgImage = image?.cgImage else { return nil }
|
|
|
+ self.init(cgImage: cgImage)
|
|
|
+ }
|
|
|
}
|