How to set height of containers in stack view?

Lachtan picture Lachtan · Dec 2, 2015 · Viewed 24k times · Source

I'd like to ask you if it's possible to set height in percentage of each container placed in vertical stack view? I want to have 3 containers in stack view. First should take 40% of screen size, second 20% and third 40%. Thank you

enter image description here

Answer

BangOperator picture BangOperator · Dec 3, 2015

'Fill proportionally' distribution type works with intrinsic content size.

So if our vertical stack(height say 600) view has 2 views, ViewA (intrinsic content height 200) and ViewB(intrinsic content height 100), the stack view will size them to ViewA(height 400) and ViewB(height 200).

Also,

  1. If all the views do not have intrinsic content height, vertical stack view will always show an IB error "Needs constraint for: Y position or Height".
  2. Views with no intrinsic height will collapse to zero height.
  3. Views that have intrinsic height will distribute themselves proportionally.

What you really want

is the 'fill' type distribution with two constraints.

  1. ViewA.height = 2* ViewB.height
  2. ViewB.height = 0.5 * ViewC.height

Thats all. Hope it helps.

enter image description here