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

//颜色生成图片
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))