iOS:颜色转图片

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
- (UIImage *)createImageWithColor:(UIColor *)color
{
CGRect rect = CGRectMake(f, f, f, f);
//创建画布
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
//填充颜色
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
//画布转图像UIImage
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
//end context
UIGraphicsEndImageContext();
return theImage;
}
  Total:    No.