Centering two buttons with Cocoa Auto Layout

后端 未结 7 1679
抹茶落季
抹茶落季 2021-02-03 22:13

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.<

7条回答
  •  旧时难觅i
    2021-02-03 22:55

    Another trick to do this is to align the right side of button to be half the size of the space away from the Center of superview, and the left side of button2 to be half the size of the space away from the Center of superview.

    This only really works if you have a superview that only surrounds the two views you want to centre though.

提交回复
热议问题