iosswiftuikitsnapkit

Custom distribution for UIStackView


I have the following UIStackView.

enter image description here

Here is the pseude-code:

let stack = UIStackView()
stack.axis = .vertical
stack.distribution = .fill

Blue, Yellow, Violet and Green views have their correct sizes (autosized labels or buttons). However, red one is being used to fill the remaining space.

I want that Violet one to fill the empty space instead of Red. Is there any way to specify which view should fill the empty space?


Solution

  • You'll need to weight each view using contentHuggingPriority.

    Try making the red view's contentHuggingPriority higher than the violet.