iOS-UIButton分类扩展(封装)
UIButton+BackgroundColor.h
#import <UIKit/UIKit.h>
@interface UIButton (BackgroundColor)
- (void)setBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state;
@end
UIButton+BackgroundColor.m
#import "UIButton+BackgroundColor.h"
@implementation UIButton (BackgroundColor)
- (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;
}
@end
最新文章
- JS产生随机数
- git高级命令
- SPOJ Play on Words
- 合并 hdfs 文件
- 记个maven无法识别JAVA_HOME的问题 Error: JAVA_HOME is not defined correctly.
- Android运行时注解
- iOS-OC-基础-NSPredicate常用方法
- 框架基础:ajax设计方案(二)---集成轮询技术
- CodeForces - 294A Shaass and Oskols
- linux 更新源miss问题
- Python中的冒泡排序
- yum 安装 python-pip 失败解决方法
- js 回文判断
- C16记技术服务支持
- 一个第三方Dart库导致的编译错误!
- rabbitmq (四) 路由
- array_reduce()使用
- [Deep-Learning-with-Python]基于Keras的房价预测
- centos7 做rails 执行rails server 报错
- volatile的语义与实现