我尝试用框架和颜色创建一个UIImage,但不知道正确的方法。
UIImage *aImage = [UIImage imageWithCIImage:[CIImage imageWithColor:[CIColor colorWithCGColor:[UIColor redColor].CGColor]]];
上述行是否正确?如何创建图像大小?请帮忙!
答案 0 :(得分:7)
制作UIImage
类别。
,例如UIImage(Color)
+ (UIImage *)imageWithColor:(UIColor *)color andSize:(CGSize)size
{
UIGraphicsBeginImageContextWithOptions(size, YES, 0);
[color set];
UIBezierPath * path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, size.width, size.height)];
[path fill];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext ();
UIGraphicsEndImageContext();
return image;
}
使用方法:
#import "UIImage + Color"
UIImage *image = [UIImage imageWithColor:[UIColor redColor] andSize:yourSize];