iOS Autolayout: two buttons of equal width, side by side

前端 未结 5 944
一整个雨季
一整个雨季 2020-11-30 16:46

I am currently having difficulty with AutoLayout. I am using interface builder and am trying to position two buttons of equal width side by side as illustrated in the follow

相关标签:
5条回答
  • 2020-11-30 17:31

    My solution is to

    1. Put a small view in the middle of two buttons and make it centre(Horizontal centre in container and vertical centre in contener as 0).
    2. Add height and width to the small view.
    3. Add buttons the constraints and give horizontal space constraints to small view.
    4. Give the small view background colour same as buttons or View's colour.

    Note: See the Screenshot.

    0 讨论(0)
  • 2020-11-30 17:32

    You can check my example - you can easy aim this, by using proportional constraint. Also you can easy aim proportional multiple UIViews. Please look attached example

    https://dl.dropboxusercontent.com/u/48223929/TestViewController.xib

    0 讨论(0)
  • 2020-11-30 17:35

    Stack layout in iOS9, will do the job really nice. Add stack view to your view and configure as follow:

    0 讨论(0)
  • 2020-11-30 17:39

    Add the following constraints

    1. Assign equal width from button1 to button2.
    2. Assign horizontal spacing between both buttons.
    3. Assign leading space from button1 to its superview.
    4. Assign trailing space from button2 to its superview.
    5. Assign top space to both the buttons.
      Let me know if it works for you.
    0 讨论(0)
  • 2020-11-30 17:50

    Follow Steps and Screenshots for easy solution


    Step-1)

    • For Button 1 : Set Constraints: (1)Leading, (2)Top or Bottom asper your need, (3)Height


    Step-2)

    • For Button 2 : Set Constraints: (1)Trailing,(2)Top or Bottom asper your need, (3)Height

    Step-3)

    • Press Ctrl + Drag From Button 1 to Button 2

    • Select Horizontal Spacing


    Step-4)

    • Select Both Button (using Command) and Add Constraints Equal Width


    OUTPUT

    Hope it Helps you :)

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