简体   繁体   中英

Xcode constraints for specific layout

I'm trying to get a specific layout in Interface Build using constraints, but can't figure out the constraints I need. I'll try and demonstrate what I'm after using a diagram. I've got a header with a background image, and then two buttons place inside it. On iPhone 5, I switch out the header for a larger one, and that causes the header to grow to the correct size, but I can't figure out what constraints I need to put on the buttons to get them to space out how I want (see iPhone 5 diagram)

On iPhone 4

-------------------------
|Button 1               | <- Header
|Button 2               |
-------------------------

On iPhone 5 (Need to figure out constraints to get this to happen)

-------------------------
|Button 1               |
|                       |
|Button 2               |
|                       |
|-----------------------|

I'd like Button 2 to centre in the space between the bottom of Button 1 and the bottom of the header view. I'd also like (though not massively important) to move Button 1 down slightly away from the top of the header. Can anyone help with this?

Wrap button2 in a UIView wrapper. Position button2 in the vertical center of this wrapper.

The wrapper should take the remaining space of the view. Attach the top edge of the wrapper to the bottom edge of button1. Attach the bottom edge of the wrapper to the bottom edge of the superview.

在此处输入图片说明

et voilà:

在此处输入图片说明

Now you just have to change backgroundColor of the wrapper.

To move button1 down you have to go into code. Connect the constraint that defines the top edge of button1 to a IBOutlet so you can change the constraint to a multiple of the views 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