Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 220
shaydawg Avatar asked Nov 28 '15 12:11

shaydawg


3 Answers

This line should resolve your problem :

yourImageView.clipsToBounds = true

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

like image 133
Tiois Avatar answered Nov 01 '22 10:11

Tiois


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]

like image 35
Kishore Kumar Avatar answered Nov 01 '22 12:11

Kishore Kumar


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

like image 1
Abhishek Avatar answered Nov 01 '22 12:11

Abhishek