用色值生成图片

  1. @interface UIImage (Color)  
  2.   
  3. + (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size;  
  4.   
  5. @end  
  6.   
  7. @implementation UIImage (Color)  
  8.   
  9. + (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size  
  10. {  
  11.     CGRect rect = CGRectMake(0, 0, size.width, size.height);  
  12.     UIGraphicsBeginImageContext(rect.size);  
  13.     CGContextRef context = UIGraphicsGetCurrentContext();  
  14.     CGContextSetFillColorWithColor(context,color.CGColor);  
  15.     CGContextFillRect(context, rect);  
  16.     UIImage *img = UIGraphicsGetImageFromCurrentImageContext();  
  17.     UIGraphicsEndImageContext();  
  18.       
  19.     return img;  
  20. }  
  21. @end
原文地址:https://www.cnblogs.com/huangzhenwei/p/5958006.html