swift根据颜色创建图片

2016-11-02  本文已影响46人  SimpleTogether

//根据颜色创建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!

}

上一篇 下一篇

猜你喜欢

热点阅读