一、绘制纯色图片
+(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 *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
二、绘制渐变色图片
/**
* 绘制渐变色的矩形UIImage
*
* @param bounds UIImage的bounds
* @param colors 渐变色数组,可以设置两种颜色
* @param gradientType 渐变的方式:0:水平渐变 1:竖直渐变 2:向下对角线渐变 3:向上对角线渐变
*
* @return 渐变色的UIImage
*/
+ (UIImage*)createGradientRectImageWithBounds:(CGRect)bounds Colors:(NSArray*)colors GradientType:(int)gradientType{
NSMutableArray *cgcolorArr = [NSMutableArray array];
for(UIColor *col in colors) {