TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Oct 2016 |
SwiftSwift Version | 3.0 |
SPMSupports SPM | ✗ |
Maintained by Gabriel Massana.
Category to handle the background color of a UIButton in normal and highlighted state.
Helps on the size of the app, avoiding to add images to handle states.
As you know iOS only allows you to set the background color of a button forUIControlStateNormal
. If you want different colors for different states, likeUIControlStateHighlighted
, you should usesetBackgroundImage: forState:
.
But this comes with a price, for every button in our app we will need an image for every state. With this category you can set the background color of a button for eitherUIControlStateNormal
orUIControlStateHighlighted
.
platform :ios, '8.0'
pod 'ButtonBackgroundColor'
Then, run the following command:
$ pod install
Drag into your project the folder /ButtonBackgroundColor-iOS
. That’s all.
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 is released under the MIT license. Please see the file called LICENSE.
$ git tag -a 2.0.0 -m 'Version 2.0.0'
$ git push --tags
Gabriel Massana
Please open a new Issue here if you run into a problem specific to ButtonBackgroundColor-iOS, have a feature request, or want to share a comment.