I am trying to achieve a stacked arrangement of simple NSViews, and for that I'm using an NSCollectionView bound to a Dictionary Controller. The result I have so far is below:
The labels on the left are bound to the controller item keys and the SegmentedControl selectedIndex to the item values.
Problem is, I have no idea how to force the subviews within NSCollectionView to conform to the container width; what happens is, they maintain their own width and when the NSCollectionView becomes too narrow horizontal scrollbar appears, like below:
I am aware of this question (and the "inverse", this one), and I've never worked much with Autolayout beyond trivial things to be honest. I am wondering, with all the fanciness that AutoLayout brings with it, is there a way of dealing with this issue without resorting to coding and using events/notifications? (I understand that observing NSViewFrameDidChangeNotification is an alternative, right?)
Thanks
Just did something very similar - except using an NSSplitView
subclass - so if I understand your question correctly you'd want to setup constraints for the subviews to attach to the sides of your superview like this:
NSDictionary * viewsDict = NSDictionaryOfVariableBindings(filler);
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[filler]|"
options:0
metrics:nil
views:viewsDict]];
You might also have to fiddle with the Content Compression Resistance Priority parameter of you subviews to achieve the desired results.
Also note that when targeting OS X 10.9 exclusively there's the new NSStackView
class:
"NSStackView is a new class in OS X 10.9. It is used to layout horizontal or vertical stacks of views using auto layout. Necessary constraints will automatically be created and modified when adding and removing views from a stack view to maintain a cohesive layout."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With