An open API service indexing awesome lists of open source software.

https://github.com/devxoul/uibutton-backgroundcontentmode

A missing background content mode for UIButton.
https://github.com/devxoul/uibutton-backgroundcontentmode

Last synced: 3 months ago
JSON representation

A missing background content mode for UIButton.

Awesome Lists containing this project

README

        

UIButton+BackgroundContentMode
==============================

[![CocoaPods](http://img.shields.io/cocoapods/v/UIButton+BackgroundContentMode.svg?style=flat)](https://cocoapods.org/pods/UIButton%2BBackgroundContentMode)

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:

```objc
[button setBackgroundImage:image forState:UIControlStateNormal];
```

Oh my god. Aspect ratio has broken. :weary:

It's time to use **UIButton+BackgroundContentMode** to keep background image aspect ratio.


Installation
------------

Use [CocoaPods](http://cocoapods.org).

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

Usage
-----

Import `UIButton+BackgroundContentMode`, then set `backgroundContentMode` of UIButton.

For example:

aspect-fit

```objc
button.backgroundContentMode = UIViewContentModeScaleAspectFit;
```



aspect-fill

```objc
button.backgroundContentMode = UIViewContentModeScaleAspectFill;
```



Finish! Set background image and enjoy coding. :tada:

License
-------

UIButton+BackgroundContentMode is under MIT license. See the [LICENSE](LICENSE) file for more info.