美文网首页
swift5.0用颜色创建一张图片

swift5.0用颜色创建一张图片

作者: 千年积木 | 来源:发表于2020-07-17 18:23 被阅读0次
extension UIImage{
    
    ///用颜色创建一张图片
   static func creatColorImage(_ color:UIColor,_ ARect:CGRect = CGRect.init(x: 0, y: 0, width: 1, height: 1)) -> UIImage {
        let rect = ARect
        UIGraphicsBeginImageContext(rect.size)
        let context = UIGraphicsGetCurrentContext()
        context?.setFillColor(color.cgColor)
        context?.fill(rect)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image!
    }
    
}

相关文章

网友评论

      本文标题:swift5.0用颜色创建一张图片

      本文链接:https://www.haomeiwen.com/subject/rplnhktx.html