How can I have the width and height of add-ins in UIStackView

Say, for example, I want to add 3 buttons to the stack view.

Button1 - 200 * 200 (1)

Button2 is 150 * 150 (0.75)

Button3 - 100 * 100 (0.5)

How can I accomplish this in an interface builder?

+19
source share
2 answers

You can do this in a storyboard using stackview

  1. Add a stack view using the Alignment Center and Distribution Fill .
  2. Restrictions on viewing the stack are centered horizontally and vertically in the center.
  3. Now add three buttons.
  4. The restrictions on button1 are height and width = 200
  5. The restrictions on button2 are height and width = 150
  6. The restrictions on button3 are height and width = 100

Installation is shown in fig:

enter image description here

You have conflicts due to the alignment property, which in your case it fills. make it a center, and it's done.

We can also add the spacing between the buttons. If we install Distribution Equal Spacing and add a height limit for a stack with a height greater than the height of the buttons.

This is a vertical view of the stack. You can check the same with horizontal stack viewing.

Hope this works for you.

+34
source

For those who are looking for a solution for UIView , here it is,

UIStackView ensures that its ordered subviews maintain the same proportion to each other as your layout grows and shrinks . However, unlike other distribution options, proportional views must have an internal content size .

0
source

All Articles