简体   繁体   中英

Xcode Auto Constraints not Working Properly

For some reason when I add constraints, by clicking "Add Missing Constraints," it actually looks worse than without constraints in the iPhone 4S simulator.

Here is how it looks in Xcode:

Xcode图像

Here is how it looks in the simulator:

模拟器图像

Notice that even with the auto constraints, the top text is hidden in the simulator. I want it to look exactly like it looks in Xcode, but I cannot figure it out. I have played around with the constraints for hours now to no avail. It looks better and better with the bigger screen size I use in the simulator, but I need it to have a universal look across all devices. What am I doing wrong?

First remove all constraint for the view.

1) Apply pin Width and Height constraint for your all three controls.

2) Apply Top space from Top Layout Guid for all three controls.

3) Apply Align Centre Horizontally in Superview of your all your three controls.

After applying above constraints your controls will appear in centre in any device.

I believe the three controls should be centre aligned with the top view and the vertical space between the three controls is constant.

The controls will automatically adjust their width according to the text given. So all you have to do is to only add the constraints for their positions. So each control will need two constraints, only for Y position, another for X position.

And of course, you can change the multiplier of the constrains to support the Landscape orientation.

在此输入图像描述

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