看到题目,遇到过这样问题的同学应该是不陌生的,没遇到过这样需求的可能会有点不知所云,通过一个颜色,转化为图片,再用,话不多说,直接上代码:
UIImage* CreateImageWithColor(UIColor *color) {
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
Hope To Help You !
技术交流群:141624834 进群请说你看的那篇博客,我们一起探讨成长