美文网首页
swift根据颜色创建图片

swift根据颜色创建图片

作者: SimpleTogether | 来源:发表于2016-11-02 14:42 被阅读46次

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

      本文链接:https://www.haomeiwen.com/subject/owbvuttx.html