Rotate the buttons evenly horizontally across the screen using autorun. Uneven distance between them.

I need to expand a series of buttons horizontally across the screen so that they are evenly distributed across the screen, unevenly distributed among themselves. The example consists of 3 buttons, they are evenly distributed so that the first button is centered on 25% of the screen width, and the others - 50%, 75% of the screen width.

It is relatively simple by manually placing them at the x, y coordinates, but I try to avoid mixing approaches.

The predominant recommendation is to use UIView between the buttons and set a limit so that the spacers are equal. This does not work if the spaced buttons have different sizes. Say there are 3 buttons labeled "A", "B", "ReallyLong." I still want them to be focused, and β€œB” in the middle of the screen. Equal spacers leave an equal distance between them, but not evenly distributed buttons. ReallyLong takes up too much space, and B is not centered.

enter image description here

+4
source share
3 answers

, . , . , , . , . .

, , , .

Constraint = "H:|[spacer0(>=0)][button0][spacer1(==spacer0)][button1(==button0)][spacer2(==spacer0)][button2(==button0)][spacer3(==spacer0)]|"

, , . , :

enter image description here

+4

X . , X trailing 0,25, 0,5 0,75 ( 0). , Xcode , Button.CenterX Superview.Trailing( ), .

+6

Apple .

, , . , , .

, , . , . .

enter image description here

- , . , .

enter image description here

:

  • 2 3 1.

  • 1, .

  • 1 .

  • spacer 1 1. , , 1000.

  • spacer 2 1
    2. - 999.

  • 3 2. , , 1000.

  • - spacer 3 .

(). , , :

enter image description here

enter image description here

+5

All Articles