Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting space between some items in stack view

Tags:

xcode

ios

People also ask

How do I use stack view auto layout?

fill. A layout where the stack view resizes its arranged views so that they fill the available space perpendicular to the stack view's axis. The simplest of the alignments, . fill constrains the leading/trailing edges of each arranged subview to the leading/trailing edge of the stack view.

How do I increase the width of a stack view?

Select the top-level stack view and in the Attributes inspector, click the + button next to Spacing: Choose Any Width and Compact Height, then select Add Variation. Set the Spacing to 10 in the new hC field: Build and run.

How do you stack view in storyboard?

The exact layout varies depending on the stack view's axis , distribution , alignment , spacing , and other properties. To use a stack view, open the Storyboard you wish to edit. Drag either a Horizontal Stack View or a Vertical Stack View out from the Object library, and position the stack view where desired.

When would you use a stack view?

Best use of stack view is that if you want to set multiple controls allinged vertically or horizontally to each other you just add all of them in stack view. stackview will handle its allignment you just need to give frame contraints to stackView.


It's an answer based on Lumialxk's reply. Choose the stack view you want to work on, and change the spacing property to your desired value.

Screen shot of the property panel


iOS 11 and above

stackView.setCustomSpacing(32.0, after: headerLabel)

For more info: Stack View Custom Spacing


Inside your horizontal stack view have three more horizontal stack views so that you can have control over spacing and distribution for each item. See screenshot below:

enter image description here


Programmatically for each view:

stackView.spacing = 10.0

If you want to make a custom spacing after each view and you need to support lower than iOS11:

Create a clear UIView with height and add it as an addArrangedSubview into the stackView.