// 根据颜色生成图片
func getImageWith(_ color: UIColor?, andHeight height: CGFloat) -> UIImage? {
let r = CGRect(x: 0.0, y: 0.0, width: 1.0, height: height)
UIGraphicsBeginImageContext(r.size)
let context = UIGraphicsGetCurrentContext()
context?.setFillColor(color!.cgColor)
context?.fill(r)
let img: UIImage? = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return img
}
网友评论