ButtonBackgroundColor 3.0.0

ButtonBackgroundColor 3.0.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布上次发布2016年10月
SwiftSwift 版本3.0
SPM支持 SPM

Gabriel Massana 维护。



  • 作者
  • Gabriel Massana

ButtonBackgroundColor-iOS

是什么

处理 UIButton 的正常和高亮状态下背景颜色的分类。

有助于减小应用程序的尺寸,避免添加图像来处理状态。

正如您所知,iOS 只允许您为 UIControlStateNormal 设置按钮的背景颜色。如果您想为不同的状态设置不同的颜色,例如 UIControlStateHighlighted,您应该使用 setBackgroundImage: forState:

但这也带来了一定的代价,对于我们应用程序中的每个按钮,我们都需要为每个状态提供一个图像。使用这个分类,您可以为一组按钮设置 UIControlStateNormalUIControlStateHighlighted 的背景颜色。

安装

Podfile

platform :ios, '8.0'
pod 'ButtonBackgroundColor'

然后,运行以下命令

$ pod install

老方法

/ButtonBackgroundColor-iOS 文件夹拖动到您的项目中。这样就完成了。

Swift 示例

 let button: UIButton = UIButton(type: .Custom)
 button.backgroundColorForStates(normal: UIColor.redColor(), highlighted: UIColor.blueColor())

Objective-C 示例

#import "ButtonBackgroundColor-Swift.h"

...

- (UIButton *)button
{
    if (!_button)
    {
        _button = [UIButton buttonWithType:UIButtonTypeCustom];
        _button.frame = CGRectMake(0.0f,
                                   100.0f,
                                   CGRectGetWidth([UIScreen mainScreen].bounds),
                                   80.0f);

        [_button bbc_backgroundColorNormal:[UIColor redColor]
                backgroundColorHighlighted:[UIColor blueColor]];
    }

    return _button;
}

不兼容

 let button: UIButton = UIButton(type: .Custom)
 button.backgroundColorForStates(normal: UIColor.redColor(), highlighted: UIColor.blueColor())

 button.highlighted = true
[button bbc_backgroundColorNormal:[UIColor redColor]
       backgroundColorHighlighted:[UIColor blueColor]];

button.highlighted = YES

许可证

ButtonBackgroundColor-iOS 在 MIT 许可下发布。请参阅名为 LICENSE 的文件。

版本

$ git tag -a 2.0.0 -m 'Version 2.0.0'

$ git push --tags

作者

Gabriel Massana

发现问题了吗?

如果您遇到特定于 ButtonBackgroundColor-iOS 的问题,或有功能请求,或者想要分享评论,请在这里打开新问题