Mr Riksson
Mr Riksson

Reputation: 560

UIButton Background image resizes

I'm working on a project where my UIButtons will have a custom background image. I'm currently only testing on the iPhone 6 Plus so the images have the sizes to match that resolution.

The image has the exact size of the button which is 414 x 226, however the iPhone still resizes, or well zoom in the image when I run it in the simulator. enter image description here

That's a picture from the Interface builder / Inspector showing the issue.

Any idea on how I can fix this?

Upvotes: 0

Views: 622

Answers (2)

Dennis Weidmann
Dennis Weidmann

Reputation: 1967

you need to set this on your Button...

myButton.layer.masksToBounds = true

Update

please try this...

myButton.imageView?.layer.masksToBounds = true

Upvotes: 0

Chengappa C D
Chengappa C D

Reputation: 1891

Try setting the content mode of UIButton to Scale to fill. And if you are comfortable with Autolayout, use constraints to set the position of UIButton (and fix the height, if thats what you want) and other components in your view. I believe with constraints properly set, it should not resize in runtime.

Upvotes: 1

Related Questions