简体   繁体   中英

Center UIImage Horizontally Constraint in UIView Not Working?

So I have been using the new Xcode 6.2 Auto Layout Preview and other features to get my app ready for all screen sizes. I am trying to constrain a UIImage to look equally the same in every screen type. I have set up the constraints, and I am looking for it look the same, although it is not. Below are the screenshots of the constraints, storyboard view, and then the final compiled product. As you can see the image is not centered.

Constraints:

在此处输入图片说明

在此处输入图片说明

Here is the compiled version, obviously off.

这是编译版本,显然已关闭。

Any help is greatly appreciated. Thanks in advance.

It is possible to meet all your constraints and have a very large width for the imageView. It has to align to a specific top and bottom edge, and then resize to width to meet the aspect ratio constraint. It seems like the width it determines is larger than the width of the screen. Basically, your image is in landscape, while the device is in portrait.

You could remove the bottom constraint, and add a constraint for the left and right edge. This would make the imageView a specific width and a flexible height.

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