UIColor转换为UIImage

2021-11-01 09:09:03 浏览数 (1)

代码语言:javascript复制
/**

color转image
*/
(UIImage)createImageWithColor: (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;
}</pre> 

0 人点赞