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 1766
余生分开走
余生分开走 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:16

    My answer is in a bit different way. I prefer not to use size class until and unless specially required. Now for your requirement i will disable size class and i will add the constraint like below.

    I will add a clear color alpha 0 UIView to the superview just above those buttons named SpacerView

    SpacerView -

    1) Leading to superView - 0 - For Alignment of SpacerView

    2) Trailing to superView - 0 - For Alignment of SpacerView

    3) Top to superView - 0 - For Alignment of SpacerView

    4) Proportional Height to SuperView - For Dynamic Sizing Height of SpacerView

    Button 1 -

    1) Leading to superview - 0 - For Alignment of Button 1

    2) Trailing to Button 2 - 0 - For Alignment of Button 1 and Button 2

    3) Proportional height to super view - 40:568 - For Dynamic Sizing Height of Button 1

    4) Equal width to Button 2 - 0 - For Sizing of Width of Button 2 equal as Button 1

    5) Equal Height to Button 2 - 0 - For Sizing of Height of Button 2 equal as Button 1

    6) Top to SpacerView - 0 - For Alignment of Button 1

    7) Center Y to Button 2 - 0 - For Alignment of Button 2 equal as Button 1

    Button 2 -

    1) Trailing to superView - For Alignment of Button 2

    Here not even a single constraint is extra as per your requirement. If you have still problem i can send you a testing repository which i will make for your understanding.

提交回复
热议问题