swift根据颜色创建图片

//根据颜色创建UIImage

funccreatImageWithColor(color:UIColor)->UIImage{

letrect =CGRect.init(x:0, y:0, width:1.0, height:1.0)

UIGraphicsBeginImageContext(rect.size)

letcontext =UIGraphicsGetCurrentContext()

context!.setFillColor(color.cgColor)

context!.fill(rect)

letimage =UIGraphicsGetImageFromCurrentImageContext()

UIGraphicsEndImageContext()

returnimage!

}

你可能感兴趣的:(swift根据颜色创建图片)