IOS button背景颜色状态设置

来源:互联网 发布:js 数组 lastindexof 编辑:程序博客网 时间:2024/04/30 00:57

关于button背景颜色(高亮状态)和(普通状态)

[self.confirmBtnsetBackgroundImage:[FunctionimageWithColor: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, [colorCGColor]);

    CGContextFillRect(context, rect);

    

    UIImage *image =UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    

    return image;

}

0 0