UIButton里有對不同狀態(tài)設(shè)置不同背景圖片的方法采幌,但沒有不同狀態(tài)對應(yīng)不同背景色的方法
在不需要切圖的情況下,我們可以采取把顏色轉(zhuǎn)成對應(yīng)的圖片設(shè)置
+(UIImage*) createImageWithColor:(UIColor*) color
{
CGRect rect = CGRectMake(0, 0, 50, 50);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image ;
}