Create NSSplitView + subview programmatically

橙三吉。 提交于 2021-02-06 12:49:58

问题


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?


回答1:


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];


来源:https://stackoverflow.com/questions/5850440/create-nssplitview-subview-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!