Centering two buttons with Cocoa Auto Layout

后端 未结 7 1670
抹茶落季
抹茶落季 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条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-03 22:53

    Basically, I have two UIButtons inside my UITableViewCell positioned below that needs to be always centered and with same widths. This is how I made it work in Xcode 7.2. I'm using Swift by the way, if that's in any way related.

    1. In the left button, I gave it a leading and bottom constraints
    2. In the right button, I gave it a trailing and bottom constraints
    3. In the right button, I gave it a leading space to the left button
    4. Lastly, in my right button, I gave it an equal width constraints to the left button.
    5. Done.

提交回复
热议问题