iOS UIColor转换为UIImage

倪炎彬
2023-12-01
+ (UIImage *)wm_imageWithColor:(UIColor *)color {
	CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
	//开启图片上下文
	UIGraphicsBeginImageContext(rect.size);
	//获取上下文
	CGContextRef context = UIGraphicsGetCurrentContext();
	//设置颜色
	CGContextSetFillColorWithColor(context, [color CGColor]);
	//设置rect
	CGContextFillRect(context, rect);
	UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
	//上下文使用完毕,关闭上下文
	UIGraphicsEndImageContext();
	//返回image
	return image;
}
 类似资料: