Encapsulating views with NSStackView
One of the most useful views in a storyboard UI is, ironically, one that the user never sees. That view is NSStackView
.
The idea is simple: Put views that are spatially related to each other into a containing view that offers support for automatically aligning, distributing, and spacing the items that are placed within it.
This offers a number of advantages:
- It's a really quick way to lay out a set of UI elements, particularly when you need to align text baselines and such, which can get a bit fiddly at times.
- It's really robust, in terms of design, since the elements within an
NSStackView
will retain their relative layout regardless of what happens outside of the view. - The default values give an immediately Apple-typical look.
This is a good example of if you can use Apple's little helpers, you probably should.
Let's take a rather messy, not yet laid out interface:
We can group-select the two buttons and the label on the left, and hit the Embed in Stack button...