ImageWithColor

倪德业
2023-12-01
@interface UIImage (Color)  
  
+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size;  
  
@end  
  
@implementation UIImage (Color)  
  
+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size  
{  
    CGRect rect = CGRectMake(0, 0, size.width, size.height);  
    UIGraphicsBeginImageContext(rect.size);  
    CGContextRef context = UIGraphicsGetCurrentContext();  
    CGContextSetFillColorWithColor(context,color.CGColor);  
    CGContextFillRect(context, rect);  
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();  
    UIGraphicsEndImageContext();  
      
    return img;  
}  
@end
 类似资料:

相关阅读

相关文章

相关问答