I have a problem with Cocoa Auto Layout and can\'t get my head around this problem. All I\'d like to achieve is to have two buttons always centered in a view as depicted below.<
If you have fixed width buttons and you want fixed distance between two then following steps can do the work :
Width
and Height
constraint
to button1
Example value: 100 height and 100 width.constraint
Equal Widths
and Equal Heights
.Horizontal Spacing
between button1
and button2
. or we can say add Leading Space
to button2
from button1
. Example value : 150button1
and add constraint
Horizontally in Container
with -125 value. constrains
like Vertical Spacing to Container
etc as per needed.Example value 125 is equals to (button1
width
/ 2) + (Horizontal Spacing
/2) which is 100/2 + 150/2 = 125.
So adding Horizontal in Container
to -125 will move the buttons
to left and that will make this layout center in screen.
Example layout and Constraints images attached below :