The minimum spacing, in points, between adjacent views in the stack view.
- macOS 10.9+
A stack view uses this property to define the minimum distance between views within a gravity area and between neighboring views in adjacent gravity areas. The default value for the
spacing property is
The automatically applied Auto Layout constraints for
spacing are shown in Table 1.
Value for constraint priority
max (NSLayoutPriorityDefaultHigh, hugging priority)
The first row in Table 1 indicates that inter-view spacing is constrained to equal the value of the
spacing property with a priority of at least NSLayoutPriorityDefaultHigh; you can increase this by setting a higher stack view hugging priority with the
The second row in Table 1 indicates that the spacing between adjacent views in neighboring gravity areas is constrained to equal the value of the
spacing property with the priority of the stack view’s hugging priority.
The third row in Table 1 indicates that inter-view spacing is allowed to grow larger than the value of the
spacing property with a priority of NSLayoutPriorityRequired.
In combination, these constraints result in the following typical stack view behavior: In a stack view whose
has property is set to
NO (the default) and whose hugging priority is left at NSLayoutPriorityDefaultLow (the default), views within a gravity area remain a fixed distance from each other (equal to the value of the
spacing property), and the distance between gravity areas grows and shrinks as the stack view grows and shrinks along its layout direction axis. If you set the
has property to
YES and use the default hugging priority, then the distance between all adjacent views, including adjacent views in neighboring gravity areas, grows and shrinks as the stack view grows and shrinks.