NSStackView + NSScrollViewâŚ
Over the years of hacking for iPhone, Iâve accumulated a certain self confidence in regards of Apples development environment and their frameworks. I know my way around Xcode if you will.
The other day I took this can-do-attitude and dove head first into MacOS development. This swimming pool wasnât too deep apparently and I was stuck after one minute trying to make a NSStackView scrollable... This. Should. Not. Be. This. Hard. Whereâs all these views coming from!? Whatâs a NSClipView?!
Anyway - I found some obscure e-mail thread on the deep web (aka not-the-first-google-result) that gave me a few hints - which eventually led to a perfectly scrollable NSStackView.
I thought Iâd share this with you - the interwebz - if someone is having the same problems I had.
In the interest of not making this tutorial way too verbose: create a new project, open storyboard, add the components.. yeah - you know the drill.
Add the views and select the inner most NSView
Add constraints to that NSView
Leading, top and trailing
Select the NSStackView
Add constraints to the NSStackView
Leading, top, trailing and bottom
Admire your creation
The stack should now scroll just fine! But as you might see, itâs building from the bottom and up. This wasnât the behaviour I was going for..
In order to fix that, weâre going to have to create a subclass of NSClipView and override the property âisFlippedâ and return true. Then change the class of the NSClipView in interface builder.
If youâd like to try this our for yourself, I uploaded my sample project on GitHub:Â https://github.com/mattiasjahnke/NSStackView-Scroll













