iOS swift-color转image

2017-07-03  本文已影响35人  青菜白玉堂

//传递颜色,size返回image

func imageFromColor(color: UIColor, viewSize: CGSize) -> UIImage{

let rect: CGRect = CGRect(x: 0, y: 0, width: viewSize.width, height: viewSize.height)

UIGraphicsBeginImageContext(rect.size)

let context: CGContext = UIGraphicsGetCurrentContext()!

context.setFillColor(color.cgColor)

context.fill(rect)

let image = UIGraphicsGetImageFromCurrentImageContext()

UIGraphicsGetCurrentContext()

return image!

}

上一篇下一篇

猜你喜欢

热点阅读