/UIButton-BackgroundContentMode

A missing background content mode for UIButton.

Primary LanguageObjective-CMIT LicenseMIT

UIButton+BackgroundContentMode

CocoaPods

A missing background content mode for UIButton.

When to use?

scale-to-fill

Let's assume that we have to set background image of UIButton. Like this:

[button setBackgroundImage:image forState:UIControlStateNormal];

Oh my god. Aspect ratio has broken. 😩
It's time to use UIButton+BackgroundContentMode to keep background image aspect ratio.


Installation

Use CocoaPods.

pod 'UIButton+BackgroundContentMode', '~> 0.1'

Usage

Import UIButton+BackgroundContentMode, then set backgroundContentMode of UIButton.

For example:

aspect-fit


button.backgroundContentMode = UIViewContentModeScaleAspectFit;



aspect-fill


button.backgroundContentMode = UIViewContentModeScaleAspectFill;



Finish! Set background image and enjoy coding. 🎉

License

UIButton+BackgroundContentMode is under MIT license. See the LICENSE file for more info.