I'd like to specify the default width of the left pane in an NSSplitView (that is, in code, because there doesn't seem to be a way in XCode to type in the default size). Here's the code that I've manage to cobble to together to achieve this, but it looks horrendously wordy. I'm new to Objective-C so perhaps there's a better way, but I don't seem to be able to just type .width on the subview (*pane). Am I missing something?

NSView *pane = [[_split subviews] objectAtIndex:0];
NSRect rect = [pane frame];
rect.size.width = 200;
[pane setFrame:rect];

PS. I know how to do the constrain[Min/Max]Coordinates, what I want to do is specify the size it will be when I run the application; at the moment it takes up 50% of the window, and I don't want that.

thanks

有帮助吗?

解决方案

Move the divider to where you want it to be with

[splitView setPosition:position ofDividerAtIndex:dividerIndex]

Divider index will be 0 if you only have two panes (i.e. one divider). This is equivalent to a user moving the divider to the setPosition, so the panes will adjust according to constraints fixed by the delegate.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top