如何使用NSTitlebarAccessoryViewController? [英] How to use NSTitlebarAccessoryViewController?
问题描述
有人可以告诉我如何使用NSTitlebarAccessoryViewController来为示例添加子视图吗?由于我是Mac编程的新手,您可能必须从基础进行解释。
Can anyone tell me how to use NSTitlebarAccessoryViewController, to add subview to a view with an example? As I am new to mac programming you may have to explain from basics. Please.
推荐答案
NSTitlebarAccessoryViewController
用于将子视图添加到Windows标题栏中。
NSTitlebarAccessoryViewController
is for adding subviews to the windows title bar.
这里是一个示例:
在界面生成器中设置视图
。转到ʻapplicationDidFinishLaunching:方法,将视图添加到标题栏。
Here is a example:
Set up a view
in interface builder. Go to the `applicationDidFinishLaunching: method to add the view to the title bar.
代码如下:
NSTitlebarAccessoryViewController* vc = [[NSTitlebarAccessoryViewController alloc] init];
vc.view = self.view;
vc.layoutAttribute = NSLayoutAttributeRight;
[self.window addTitlebarAccessoryViewController:vc];
您可以使用视图的大小来使其适合标题栏。
You can play with the size of the view to make it fit into the title bar.
更新
OS X 10.11引入了新的 layoutAttribute
左
。
现在总共有三个 layoutAttribute
。 底部
在titleBar(如tabBar)下方添加一个条,并在左
/ 右
将子视图放在titleBar内。
OS X 10.11 introduced the new layoutAttribute
left
.
There are now three layoutAttribute
s in total. bottom
adds a bar beneath the titleBar (like the tabBar) and left
/right
places your subview within the titleBar.
这篇关于如何使用NSTitlebarAccessoryViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!