按钮背景颜色
2015-11-23 10:36
281 查看
- (void)setBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state {
[self setBackgroundImage:[UIButton imageWithColor:backgroundColor] forState:state];
}
+ (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;
}
[self setBackgroundImage:[UIButton imageWithColor:backgroundColor] forState:state];
}
+ (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;
}
相关文章推荐
- linux设备模型之总线,设备,驱动模型
- 不能小瞧的数组——数组用法的挖掘
- WebService工作原理
- Google Guava官方教程(中文版)
- hdu5569/#63 (div.2) 1003
- 利用接口回调实现Fragment之间的跳转
- JSTL标签 参考手册(手动整理)
- Netlink技术-在Linux 下用户空间与内核空间数据交换的方式
- linux查找文件
- 机器学习之三:logistic回归(最优化)
- Andriod学习笔记1:代码优化总结1
- CSS3实现鼠标hover的过渡效果
- Bootstrap select(选择列表)
- Ajax+PHP+MySQL 登陆示例
- jQuery中append、insertBefore、after与insertAfter方法注意事项
- GOOGLE地图街景预览默认的退出按扭显示
- Android开发必知--WebView加载html5实现炫酷引导页面
- 利用MediaExtractor和MediaMuxer实现视频剪切
- javascript中style.left和offsetLeft的用法说明
- Android计步器开发