swift 如何把 颜色直接换换成图片
func creatImageWithColor(color:UIColor)->UIImage{
let rect = CGRectMake(0.0, 0.0, 1.0, 1.0)
UIGraphicsBeginImageContext(rect.size)
let context = UIGraphicsGetCurrentContext()
CGContextSetFillColorWithColor(context, color.CGColor)
CGContextFillRect(context, rect)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
本文介绍了一个Swift函数,该函数能够将指定的颜色转换为一个单一颜色的图片。通过使用UIGraphicsBeginImageContext和CGContextAPIs,可以创建一个指定颜色填充的图片。

2957

被折叠的 条评论
为什么被折叠?



