使用自定义的颜色生成图片
class func imageWithColor(color:UIColor) -> UIImage
{
let rect = CGRect(x: 0.0, y: 0.0, width: 1.0, height: 1.0)
UIGraphicsBeginImageContext(rect.size)
let context:CGContext = UIGraphicsGetCurrentContext()!
CGContextSetFillColorWithColor(context, color.CGColor);
CGContextFillRect(context, rect);
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
本文介绍了一种使用UIColor创建自定义颜色图片的方法。通过定义一个类函数classfuncimageWithColor, 可以设置图片的尺寸并填充指定的颜色。

427

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



