美文网首页
iOS---颜色生成图片(Swift)

iOS---颜色生成图片(Swift)

作者: ray_1942 | 来源:发表于2017-08-15 17:55 被阅读0次
//颜色生成图片
func createImage(_ color: UIColor)-> UIImage{
    let rect = CGRect.init(x: 0.0, y: 0.0, width: 1.0, height: 1.0)
    UIGraphicsBeginImageContext(rect.size)
    let context = UIGraphicsGetCurrentContext()
    context?.setFillColor(color.cgColor)
    context?.fill(rect)
    let image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    return image!
}

相关文章

网友评论

      本文标题:iOS---颜色生成图片(Swift)

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