A missing background content mode for UIButton.
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.
Use CocoaPods.
pod 'UIButton+BackgroundContentMode', '~> 0.1'
Import UIButton+BackgroundContentMode
, then set backgroundContentMode
of UIButton.
For example:
button.backgroundContentMode = UIViewContentModeScaleAspectFit;
button.backgroundContentMode = UIViewContentModeScaleAspectFill;
Finish! Set background image and enjoy coding. 🎉
UIButton+BackgroundContentMode is under MIT license. See the LICENSE file for more info.