Search code examples
uitableviewautolayoutios-autolayoutuistackview

UIStackview fill proportionally in a UITableviewCell takes incorrect frame


Adding proportional fill setting in a UIStackview won't let the view stretch properly. Is this the expected behaviour? enter image description here


Solution

  • 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).

    Here in IB what you see is not what you get. Dragging to make frames change is useless. Just run the app.

    You will see the expected behaviour only when the child views somehow get the intrinsic/constrained height.

    How it looks in IB Here the top stack view has views constrained to be of height minimum 10 and 30, i.e. ration 1:4.

    enter image description here

    What we really get Top stack view is what we had expected to look like. View with height in ratio 1:4. And bottom one with ratio 1:1, not expected. enter image description here