0

I've got a view with a UIButton in it. I've got some animations that, among others, scale the button down.

The problem is that the button is actually scaling well following the constraints when it only has text, but when I set an image either as its image or its backgroundImage, the button is not scaling anymore.

I've tried playing with contentModes of both the UIButton and its inner imageView with no results (I've tried, literally, all the possible answers of this, this, this and this stackoverflow questions).

Any hint? Thank you all in advance

UPDATE

I've noticed that the issue is with UIImageViews, not UIButtons (the problem with the button was due to the imageView inside it).

Community
  • 1
  • 1
sonxurxo
  • 5,648
  • 2
  • 23
  • 33

2 Answers2

1

I think your UIButton does resize, but the ImageView inside does not. The ImageView of the UIButton is always displaying normal image size.

The only possibility I found is to put another UIImageView below the Button with constraints top/bottom/left/right to the Button. This one can be perfectly adjusted.

I use subclassed buttons for that with their own ImageView inside. There you need to be careful to put userInteractionEnabled = false on the ImageView.

Christian
  • 4,596
  • 1
  • 26
  • 33
0

Finally I've got it.

In both cases (UIButton and UIImageView), you have to adjust Content Compression Resistance Priority to let the view to scale down. In my case, setting it to 749 was enough.

sonxurxo
  • 5,648
  • 2
  • 23
  • 33