Jeef
Jeef

Reputation: 27265

IOS AutoLayout : Equi-vertical spacing for 6 buttons

I have six buttons in a vertical line in a container view. I want to have them autoLayout such that if i change the height of the container they are still equi-spaced vertically through out the container

--------
Button 1

Button 2

Button 3

Button 4

Button 5

Button 6
--------

How do I avoid this:

--------
Button 1

Button 2

Button 3

Button 4

Button 5

Button 6






--------

And get something like this:

--------

Button 1


Button 2


Button 3


Button 4


Button 5


Button 6

--------

I see there are constraints for "equal height" but i could not find equal spacing constraints. Is something like this possible?

Upvotes: 1

Views: 211

Answers (1)

Zev Eisenberg
Zev Eisenberg

Reputation: 8148

One solution is to create transparent or hidden views that go between the buttons. Set your spacer views’ heights equal to each other, your buttons’ heights equal to each other, and pin their tops and bottoms together.

Or you could use something like rz_distributeSubviews:vertically: from RZUtils, which does this layout mathematically.

Upvotes: 2

Related Questions