1、颜色->图片方法
- (UIImage *)imageWithColor:(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 *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
本文介绍了一种使用UIColor创建UIImage的方法。通过定义一个返回UIImage的方法,利用UIGraphicsBeginImageContext开始图像上下文,设置填充颜色并填充指定的矩形区域,最终获取到所需的UIImage。

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



