Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically resizing NSSplitView

I used to use and love RBSplitView, however I failed at reimplementing it programmatically as a certain version of xcode does not support IB plugins anymore.

Therefore I went back to using NSSplitView. NSSplitView is fine for what I need, the thing is that the autoSave of NSSplitView is broken. So I decided to implement it myself.

The thing I am doing at the moment is resizing 1 of the subviews of the NSSplitView.

What is the proper way of resizing an NSSplitView? - setPositionOfDivider:itIndex: should be the way to go ( haven't tried it ), however I do not know how to get the current position of the divider.

-- thanks in advance

like image 440
Antwan van Houdt Avatar asked Mar 04 '11 14:03

Antwan van Houdt


2 Answers

In my experience, NSSplitView hates you and wishes you harm. RBSplitView is so much better, it is worth IMO the headache of programatic layout (and I've been so burned with the ShortcutRecorder IB plugins that I will never go back to IB plugins).

That said....

The only way that I know of to determine the current position of the divider is to look at the subviews, find the divider's view, take it's frame, and work out its position keeping in mind the dividerThickness. It is insane that you have to write that code, but the code isn't that incredibly difficult, and you can put it in a category.

Or go back to RBSplitView while you still can, if your needs are ever going to be complicated.

like image 94
Rob Napier Avatar answered Nov 15 '22 16:11

Rob Napier


I'm using Swift here but the same method should exist in Objective C:

mySplitter.setPosition(123, ofDividerAtIndex: 0)
like image 41
Marc Fearby Avatar answered Nov 15 '22 17:11

Marc Fearby