写一个UIImage的类扩展
.h
#import <UIKit/UIKit.h>
@interface UIImage (BLHImage)
+ (UIImage *)blh_imageWithColor:(UIColor *)color;
@end
.m
#import "UIImage+BLHImage.h"
@implementation UIImage (BLHImage)
+ (UIImage *)blh_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;
}
@end
调用的时候
[self.confirmButton setBackgroundImage:[UIImage blh_imageWithColor:UIColorFromRGBOne(200)] forState:(UIControlStateDisabled)];