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

2017-08-15  本文已影响0人  ray_1942
//颜色生成图片
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!
}
上一篇 下一篇

猜你喜欢

热点阅读