Instance Method

setVisibilityPriority(_:for:)

Sets the Auto Layout priority for a view to remain attached to the stack view when Auto Layout reduces the stack view’s size.

Declaration

func setVisibilityPriority(_ priority: NSStackView.VisibilityPriority, for view: NSView)

Parameters

priority

The visibility priority for a specified view. Valid values are those in the NSStackView.VisibilityPriority enumeration.

aView

The view whose visibility priority you are setting.

Discussion

When Auto Layout reduces the stack view’s size (such as when a user reduces the size of the window containing the stack view), causing one or more views to no longer fit, the stack view detaches views in order of increasing visibility priority. A view with lower visibility priority detaches before a view with higher visibility priority. A set of views with identical, detachable visibility priority are all detached or reattached together. A view with the highest possible visibility priority never detaches.

A view in a detached state is not present in the stack view’s view hierarchy, but it still consumes memory.

The default visibility priority for a view is NSStackViewVisibilityPriorityMustHold, resulting in the view never detaching.

To allow a view to detach as needed by the stack view, set a visibility priority of NSStackViewVisibilityPriorityDetachOnlyIfNecessary. To force a view to detach regardless of the enclosing view’s size, set a visibility priority of NSStackViewVisibilityPriorityNotVisible. To explicitly reattach a view to a stack view, set a visibility priority of NSStackViewVisibilityPriorityMustHold.

See Also

Configuring Views in a Stack View

func customSpacing(after: NSView) -> CGFloat

Returns the custom spacing, in points, between a specified view in the stack view and the view that follows it.

func setCustomSpacing(CGFloat, after: NSView)

Specifies custom spacing, in points, to employ between a specified view and the view that follows it in the stack view.

func visibilityPriority(for: NSView) -> NSStackView.VisibilityPriority

Returns the visibility priority for a specified view in the stack view.