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

最新文章

  1. JS产生随机数
  2. git高级命令
  3. SPOJ Play on Words
  4. 合并 hdfs 文件
  5. 记个maven无法识别JAVA_HOME的问题 Error: JAVA_HOME is not defined correctly.
  6. Android运行时注解
  7. iOS-OC-基础-NSPredicate常用方法
  8. 框架基础:ajax设计方案(二)---集成轮询技术
  9. CodeForces - 294A Shaass and Oskols
  10. linux 更新源miss问题
  11. Python中的冒泡排序
  12. yum 安装 python-pip 失败解决方法
  13. js 回文判断
  14. C16记技术服务支持
  15. 一个第三方Dart库导致的编译错误!
  16. rabbitmq (四) 路由
  17. array_reduce()使用
  18. [Deep-Learning-with-Python]基于Keras的房价预测
  19. centos7 做rails 执行rails server 报错
  20. volatile的语义与实现

热门文章

  1. mysql对子查询的优化改写
  2. redis 介绍与操作
  3. jquery判断input选中事件
  4. 43、扩展原理-@EventListener与SmartInitializingSingleton
  5. 关于https的五大误区
  6. 什么是webpack模块化构建工具
  7. LOJ P10171 牧场的安排 题解
  8. 利用webuploader实现超大文件分片上传、断点续传
  9. 数据结构实验之图论七:驴友计划【迪杰斯特拉算法】(SDUT 3363)
  10. 【原创】go语言学习(三)字符串串、时间和日期类型