转自:http://blog.youkuaiyun.com/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;
}
本文介绍了一种在iOS开发中为UIButton设置不同状态背景颜色的方法。通过创建一个颜色到图片的转换函数,可以轻松地为按钮设置普通状态和高亮状态下的背景颜色。
1179

被折叠的 条评论
为什么被折叠?



