通过自绘背景图改变按钮颜色

自绘一张背景图

- (UIImage*)createImageWithColor: (UIColor*) color

{
    CGRect rect=CGRectMake(0,0, 1, 1);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return theImage;

}

 [titleButton setBackgroundImage:[self createImageWithColor:[UtilityHelper colorWithHexString:@"#ededed"]] forState:UIControlStateHighlighted];

你可能感兴趣的:(通过自绘背景图改变按钮颜色)