使用UIColor颜色对对象生成UIImage对象,代码如下
- (UIImage *)createImageWithColor:(UIColor *)color
{
CGRect rect = CGRectMake(0.0f,0.0f,1.0f,1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context =UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [colorCGColor]);
CGContextFillRect(context, rect);
UIImage *theImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
本文介绍如何通过Objective-C的UIColor对象来创建纯色的UIImage。代码中展示了创建过程,包括设置填充颜色,填充矩形区域,以及从当前图形上下文获取图像。

489

被折叠的 条评论
为什么被折叠?



