Auto Layout Issues iOS

82 views Asked by At

I have added an Imageview to my View.(Simulated Metrices Size:Iphone 3.5 inch).

Constarints Added to the ImageView as follows:

Horizontal Space -(-3) Horizontal Space Vertical Space - (141) Vertical Space - (67)

Imageview Frame = (0,67,323,272)

This image looks fine in Iphone 4s Simulator.

But the image gets elongated in Iphone 5s and 6 and 6Plus simulators.

Again if i am doing the whole thing in a view of Size iphone 4.7 inch The image gets shortened in a iphone 4s simulator.

How to solve this issue ??

2

There are 2 answers

0
katzenhut On BEST ANSWER

The Frame of your UIImageView will adjust itself according to your layout constraints. the constraints are depending in the size of the screen, so the imageview will change its size depending on the device that the app runs on. to solve this, you can either set the contentMode of the imageview to UIViewContentModeScaleAspectFit,

myImageview.contentMode = UIViewContentModeScaleAspectFit;

or you can change the constraints to have a fixed height instead of a variable one. but changing the content mode is probably easier ;)

1
Dante Puglisi On

It not clear what you are seeking to do. If you constraint the images view's width and height and just set it's horizontal and vertical space the image won't elongate. But, if you want to have the image view in different sizes depending on the device then play with the image setting in the image view's storyboard settings at the right.