All Projects → devxoul → UIButton-BackgroundContentMode

devxoul / UIButton-BackgroundContentMode

Licence: MIT license
A missing background content mode for UIButton.

Programming Languages

objective c
16641 projects - #2 most used programming language
ruby
36898 projects - #4 most used programming language

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].