Auto Layout with UIImageView is producing incorrect view layout when an image is shown

201 views Asked by At

I have an UIImageView in my app and it resizes perfectly according to the constraints that I set to it. But when I load an image into the UIImageView, it messes up everything. What could be causing the problem?

Here are some screenshots attached:

(The blue square is the ImageView)

As you can see, there is a UITextView above the UIImageView which should be visible like here:

But, when an image is loaded into the UIImageView, it stretches into a square for some weird reason, hiding the UITextView above it..

enter image description here

EDIT:

My constraints attached to the UIImageView enter image description here

1

There are 1 answers

0
vibhor On

use this

imageView.contentMode = UIViewContentModeScaleToFill;