Override Interval for UIStackView

I often find that a UIStackView ideal for a particular layout, except that I need some kind of variable distance between organized subviews. UIStackView uses the spacing to arrange views along its axis, but is there a way to override them? For example, I would like to add one manual constraint, using a visual format to determine the required spaces, and somehow de-priorities for representing the stack.

I could, of course, abandon UIStackView , but the ability of the stack to return the space between hidden subviews is rather painful for manual replication (for example, adding and removing restrictions based on which views are hidden). I also tried wrapping individual subzones in my own stack views so that I could use the layoutMargins stack to add a top margin. But this requires managing your own hidden state-shell-stack in addition to what is contained in its view (unexpectedly for me - UIStackView , whose arrangedSubviews all hidden, does not automatically hide, therefore it does not give its interval and the fields return to their own supervision )

+6
source share
1 answer

From iOS 11 you can use:

 stackView.setCustomSpacing(spacing: CGFloat, after: UIView) 
+2
source

All Articles