ButtonBackgroundColor 3.0.0

ButtonBackgroundColor 3.0.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Oct 2016
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Gabriel Massana.



  • By
  • Gabriel Massana

ButtonBackgroundColor-iOS

What is it?

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.

Installation

Podfile

platform :ios, '8.0'
pod 'ButtonBackgroundColor'

Then, run the following command:

$ pod install

Old school

Drag into your project the folder /ButtonBackgroundColor-iOS. That’s all.

Example Swift

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

Example 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;
}

Do not working with

 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

License

ButtonBackgroundColor-iOS is released under the MIT license. Please see the file called LICENSE.

Versions

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

$ git push --tags

Author

Gabriel Massana

Found an issue?

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.