UIStackView Layout

789 views Asked by At

I would like to have two UIButtons side by side in a UIStackView both at 50% of the view. When I drag two buttons into the Stack View, the first one takes up the majority of the view and the other is the smallest width it can be. Should I be doing something else? Thanks

3

There are 3 answers

0
Nilesh Patel On

You are doing right, but you may missed to do below thing.

You need to set the UIStackViewDistribution & UIStackViewAlignment property as per your need.

The distribution property determines the layout of the arranged views along the stack’s axis.

The alignment property determines the layout of the arranged views perpendicular to the stack’s axis.

Refer this for more info.

0
Leszek Zarna On

You need additionally add constraint that buttonA.width = buttonB.width.

0
Rob Norback On

You need to set your UIStackViewDistribution property to Fill Equally to get the 50/50 distribution.

enter image description here