转自:http://blog.csdn.net/qq_20176153/article/details/52036422
关于button背景颜色(高亮状态)和(普通状态)
[self.confirmBtn setBackgroundImage:[Function imageWithColor:RGB(244, 152, 71)] forState:UIControlStateNormal];
封装类方法掉用:
// 颜色转换为背景图片
+ (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;
}