Akeno Akeno - 1 year ago 118
iOS Question

"width" constraint of UIImageView ignored when using "Aspect Fill" (XCode, Auto-Layout)

So, what I want to do is: On the right (see the image below) you see a slim bar (it's a UIView). It's pinned 100 to the top, 100 to the bottom and 10 to the right. That works fine.
The constraints I set to the gray bar

Then I added an UIImageView with some placeholder image of a mountain. I want it to be next to the gray bar. So I aligned the top, bottom and trailing to the gray bar and set a fixed width.

("view" is my gray bar)

the constraints I set to the UIImageView

Everything works fine. That's what it looks like in the storyboard and preview window:

What it looks like in the storyboard and preview window

It also looks the same in the simulator.
Now, I changed the UIImage to "Aspect Fill". Nothing changed in the preview. But now the app inside the simulator looks weird:

What the app looks like with "Aspect Fill"

I don't know why, but it is ignoring the width I set and it also doesn't align to the gray bar anymore.

What can I do?

Please tell me If you need more information. I'm not sure what is important :)

Answer Source

set clipsToBound to TRUE property of UIImageView.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download