测试已测试 | ✓ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布上次发布 | 2016年10月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Gabriel Massana 维护。
处理 UIButton 的正常和高亮状态下背景颜色的分类。
有助于减小应用程序的尺寸,避免添加图像来处理状态。
正如您所知,iOS 只允许您为 UIControlStateNormal
设置按钮的背景颜色。如果您想为不同的状态设置不同的颜色,例如 UIControlStateHighlighted
,您应该使用 setBackgroundImage: forState:
。
但这也带来了一定的代价,对于我们应用程序中的每个按钮,我们都需要为每个状态提供一个图像。使用这个分类,您可以为一组按钮设置 UIControlStateNormal
或 UIControlStateHighlighted
的背景颜色。
platform :ios, '8.0'
pod 'ButtonBackgroundColor'
然后,运行以下命令
$ pod install
将 /ButtonBackgroundColor-iOS
文件夹拖动到您的项目中。这样就完成了。
let button: UIButton = UIButton(type: .Custom)
button.backgroundColorForStates(normal: UIColor.redColor(), highlighted: UIColor.blueColor())
#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 的问题,或有功能请求,或者想要分享评论,请在这里打开新问题。