Reputation: 560
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.
That's a picture from the Interface builder / Inspector showing the issue.
Any idea on how I can fix this?
Upvotes: 0
Views: 622
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
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