简体   繁体   中英

Auto Layout Issues iOS

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 ??

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 ;)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM