2019-03-22

2019-03-22  本文已影响0人  Angel_梅丹佐

iOS 根据给定的颜色(Color)生成 image

废话不多说直接上代码:

/*
  color :需要生成的图片颜色
 返回 一个  UIImage 类型的 image
*/
+ (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;
}
上一篇下一篇

猜你喜欢

热点阅读