+ (UIImage *)df_ImageByColor:(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 *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
根据颜色创建image
最新推荐文章于 2023-06-12 15:19:20 发布
该代码段展示了如何在iOS中通过指定的颜色来创建一个1x1像素的UIImage对象。方法`df_ImageByColor:`接收一个UIColor参数,利用UIGraphicsImageContext进行绘制并填充颜色,最终获取填充色的图片。
摘要由CSDN通过智能技术生成