I want two buttons to have equal width and position themselves proportionally in all screens sizes from the top of the scree using autolayout?

后端 未结 6 1810
余生分开走
余生分开走 2021-01-27 01:43

Attaching the view i am planning to design. I would like to position the Buttons with respect to Superview and their Width and Height must increase proportionally to the Screen

6条回答
  •  不要未来只要你来
    2021-01-27 02:39

    This is an example just for one row of your buttons, so they can be reused for other UI elements.

    Put these constraints onto your buttons:

    LEFT BUTTON:

    • left leading constraint
    • top leading constraint
    • height constraint

    RIGHT BUTTON

    • right trailing constraint
    • top leading constraint
    • height constraint

    And constraints related to both buttons: (you need to select both buttons to be able to apply relation constraints)

    • spacing constraint between buttons
    • equal width of these buttons

    In Interface Builder it looks like this:

    And these layout is universal, so I chose some device sizes to present:

    iPhone 5

    iPhone 6

    iPhone 6 Plus

    ... etc.

提交回复
热议问题