zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    第二阶段冲刺记录八
    用户体验评价
    找水王
    第二阶段冲刺记录七
    第二阶段冲刺记录六
    第14周学习进度
    第二阶段冲刺记录五
    第二阶段冲刺记录四
    第一阶段意见评论
    IP协议号大全
  • 原文地址:https://www.cnblogs.com/linxiu-0925/p/5421077.html
Copyright © 2011-2022 走看看