How to align two buttons equidistance from the centre of the UIView

后端 未结 3 1872
隐瞒了意图╮
隐瞒了意图╮ 2021-02-06 07:29

I am working with auto layout . Facing on interesting issue . Fortunately overcame from it for the time but need to know the best way to solve it .

相关标签:
3条回答
  • 2021-02-06 08:07

    I faced the same problem. I resolved using the idea i got from rdelmar's answer.

    This is what I did.

    For left button:

    1. Added the constraint to 'Center - Horizontally in container'
    2. Then changed the multiplier to 0.5 instead of 1 for that constraint.

    For right button:

    1. Added the constraint to 'Center - Horizontally in container'
    2. Then changed the multiplier to 1.5 instead of 1 for that constraint.

    Let me know if it worked for you.

    0 讨论(0)
  • 2021-02-06 08:13

    try Aligning leading edge of your btn2 and trailing edge of your btn1 with center y of your view set constant to 0 and multiplier 200:160 and 120:160 respectively where your center y is second item

    0 讨论(0)
  • 2021-02-06 08:22

    You can do this in the storyboard (or xib) by using constraints to the right edge of the screen -- the value of the right edge is the same as the width of the screen, so you can use that for calculations. For the left button you want its trailing edge to equal the superview's right edge times 0.375 (0.5 minus .125 which is half of your 25% requirement). the right button would have its leading edge equal to right edge of superview times 0.625 (.5 + .125).

    The constraints look like this,

    enter image description here

    enter image description here

    0 讨论(0)
提交回复
热议问题