Reputation: 1213
I am having a problem with the button image. I have a green background and an icon. The problem is that on larger screens the image stretches due to the button also stretch to the size of the screen.
I found several other topics they were talking about something, but none of them helped me solve this problem.
The next best picture explains the problem:
Upvotes: 1
Views: 393
Reputation: 7549
If you want your button to look like the 3rd image, you will have to use an image of that size and resolution.
Alternatively, you can set contentMode on your UIButton
's imageView object. Use this line of code in your viewDidLoad
function
button.imageView!.contentMode = UIViewContentMode.ScaleAspectFit
When your constraints increase the size of your button, the image used inside it will abide by the contentMode property set. Using those you can stretch it, which it's doing right now, or you can keep the aspect ratio, in which case it will show empty space on sides.
Upvotes: 1
Reputation: 157
It look like your constraints doesn't take on consideration the size of the asset.
You should set a Width and a Heigth constraints to your image asset.
Upvotes: 0
Reputation: 8147
Play around with the content mode settings, try 'Aspect fit' instead of the currently selected.
Upvotes: 0