如何自动绘制带有边框和颜色的UIImage? [英] How to auto draw an UIImage with frame and color?
本文介绍了如何自动绘制带有边框和颜色的UIImage?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用边框和颜色创建UIImage,但不知道正确的方法。
I try something to create an UIImage with a frame and color but don't know what the correct way.
UIImage *aImage = [UIImage imageWithCIImage:[CIImage imageWithColor:[CIColor colorWithCGColor:[UIColor redColor].CGColor]]];
以上一行正确吗?如何创建图像尺寸?
Is the above line correct? How to create image size? Please help!
推荐答案
创建 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];
这篇关于如何自动绘制带有边框和颜色的UIImage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文