有时候在开发的过程中,我们需要一张纯色的图片,这是我们就可以自己用代码创建
一张自定义尺寸和颜色的图片,灰常方便
ios 的drawRect是很神奇的一个东西。
可以直接绘制位图,并得到位图。
+ (UIImage *)createImageWithColor:(UIColor *)color frame:(CGRect)rect
{
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}