Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Starting Position of NSSplitView divider

How can I set the start position of a NSSplitView?

The closest thing I've found that looks like it would work is setPosition

//Set splitView position.
[splitView setPosition:330 ofDividerAtIndex:0];

This doesn't seem to do anything though, my splitview still starts with the divider in the center.

ANy ideas?

like image 635
aroooo Avatar asked Aug 16 '12 20:08

aroooo


Video Answer


2 Answers

You don't set the position of the divider, you set the sizes of your NSSplitView's subviews. The divider is then repositioned automatically.

This is how I positioned my divider and subview size (in swift):

let subview: NSView = mySplitView.subviews[1] as NSView
subview.setFrameSize(NSMakeSize(subview.frame.size.width, 100))
like image 162
Bjorn Avatar answered Sep 24 '22 15:09

Bjorn


NSSplitView needs initial non-sized bounds to make them layout correctly. If your view has zero-size, then it will not show expected layout.

The best way is providing non-zero layout (this is what IB does), but sometimes this is impossible.

If you cannot provide non-zero size, then I think you have to provide proper - (void)splitView:(NSSplitView *)splitView resizeSubviewsWithOldSize:(NSSize)oldSize delegate method implementation to layout everything manually yourself. (this is my current best practice)

like image 43
eonil Avatar answered Sep 24 '22 15:09

eonil