Having reviewed most of Apple's (paucity) of documentation regarding NSStackView, plus the wise words of the greater Internet, including the collective wisdom of Stackoverflow, a problem remains.
Any NSView I add programmatically to my (IB instantiated) NSStackView, visually locate themselves to the bottom of their respective gravity area. Hence they overlay each other and don't behave like an expected "stack" of views with appropriate spacing.
Each of the gravity areas seem somehow compressed and unable to accommodate any more views. The more I apply NSStackView.addView to a gravity area the slimmer the existing views become.
I would expect NSStackView to naturally expand to accommodate the .size of the embedded views.
Any wise counsel is most appreciated ...
---more details—</p>
I place the StackView into the main window using interface builder. I can then add other views into areas of the stack in interface builder, such as buttons. These stack and layout as expected in IB and when running.
However, when I add or insert any view programmatically to any gravity area their bottom edge is positioned vertically down to the bottom edge of the StackView. This layout behaviour is the same for a vertical or horizontal stack.
Consequently, if I add more than one view programmatically they are sized OK and display but overlap. I am using 'NSBox' objects as views (for now) and they are sized using '.sizeToFit()'. I can see that their '.bounds.height' and 'width' are non zero.
I'm not sure how to set or log the intrinsic content size. That might be the next thing to try.
—no luck—
So, I have now worked rigorously through all permutations of: compression, hugging, (non-zero) intrinsic sizing, constraints, no constraints and various types of NSViews, but ... if I '.addView(...)' or '.insertView(...)' more than once, in any 'NSStackView' gravity area, the subsequent views overlay the previous ones and position themselves on the particular baseline. This is the edge closest to the floor of my office, regardless of the stack orientation.
Any 'NSStackView' and AutoLayout help, either emotional or technical, is most appreciated.