Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create NSSplitView + subview programmatically

I am trying to create a horizontal NSSplitView programmatically and to add it 2 subviews. Unfortunately, if I have no issue to create the splitview, I do not know how to add the subview.

Do you have any idea to do it?

like image 394
AP. Avatar asked May 01 '11 18:05

AP.


1 Answers

You add panes to a split view the same way you add subviews to any view. Each of the split view's subviews will get its own pane. You can use the adjustSubviews method to automatically resize the views so that each pane is the same size.

This example code will create a split view which fills its window and has 3 text views split vertically.

NSSplitView *splitView = [[NSSplitView alloc] initWithFrame:[[theWindow contentView] bounds]];
NSTextView *textView1 = [NSTextView new];
NSTextView *textView2 = [NSTextView new];
NSTextView *textView3 = [NSTextView new];
[splitView addSubview:textView1];
[splitView addSubview:textView2];
[splitView addSubview:textView3];
[splitView adjustSubviews];
[[theWindow contentView] addSubview:splitView];
[textView3 release];
[textView2 release];
[textView1 release];
[splitView release];
like image 155
ughoavgfhw Avatar answered Oct 17 '22 13:10

ughoavgfhw