+ (UIImage *)imageWithColor:(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 *image =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
本文介绍了一种使用指定UIColor颜色创建UIImage的方法。通过设置绘图上下文的颜色填充矩形区域,并从中获取图片。此方法适用于需要根据颜色动态生成简单图像的场景。

1839

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



