iphone - AutoLayout: Vertically centering two UIViews in a superview that can resize -


i have 2 uibuttons, 1 on top of other, in superview height can resized. 2 buttons should have constant vertical spacing between them, top , bottom spacing should resize 2 buttons stay centered in superview resizes.

i tried creating 2 less-than-or-equal constraints (with equal priority) on spacing superview each button, constant vertical spacing between buttons, shown below: enter image description here

(the reason why it's less-than-or-equal here because view defined @ given height in ib 4" screens, can shrunk 3.5" screens.) however, doesn't trick, can see screenshot while app running: enter image description here

it's if want able tell autolayout 2 constraints should have equal values, if both set "less-than-or-equal". there way i'm trying do, or perhaps better way?

this trivial in ib.

1) ⌃ drag button1 top. select "center horizontally in container".

2) ⌃ drag button1 left. select "center vertically in container".

3) same button2.

4) thing left size buttons because looks like.

enter image description here

this trivial.

5) ⌃ drag button1 left. select "leading space container margin".

6) ⌃ drag button1 right. select "trailing space container margin".

7) exact same thing button2.

the finished product, looks (nb didn't quite center them, have enough):

enter image description here

enter image description here


Comments