6
votes

I have a UIImageView and used autolayout to add height and width constraints (and other ones as well). There are no conflicting constraints or warnings. I am querying an image from a database and setting the imageview's image to that image. However, the image is showing up with a much larger height than I have specified via constraints. How do I fix this?

3

3 Answers

2
votes

This line should resolve your problem :

yourImageView.clipsToBounds = true

You can do it in Storyboard by checking the "Clip Subviews" of your UIImageView element.

1
votes

1

   YourImageView.contentMode=UIViewContentModeScaleAspectFit;

May be the problem is coming because of your contentMode ,so please your imageView content mode.

2.if you are developing application for a single phone then use aspect fit for that[constraints]

1
votes

If you are getting image from server then you should resize the image according to your imageView size ...its a best practice.