shaydawg
shaydawg

Reputation: 1203

Image Height Constraint Not Working

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?

Upvotes: 7

Views: 2379

Answers (3)

Kishore Kumar
Kishore Kumar

Reputation: 4375

  1. YourImageView.contentMode=UIViewContentModeScaleAspectFit;
    

    Maybe 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]

Upvotes: 1

Tiois
Tiois

Reputation: 1559

This line should resolve your problem :

yourImageView.clipsToBounds = true

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

Upvotes: 3

Abhishek
Abhishek

Reputation: 509

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

Upvotes: 1

Related Questions