How to use NSTitlebarAccessoryViewController?

倖福魔咒の 提交于 2019-12-06 08:27:45

问题


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.


回答1:


NSTitlebarAccessoryViewController is for adding subviews to the windows title bar.

Here is a example: Set up a view in interface builder. Go to the `applicationDidFinishLaunching: method to add the view to the title bar.

The code would be the following:

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.

Update

OS X 10.11 introduced the new layoutAttribute left. There are now three layoutAttributes in total. bottom adds a bar beneath the titleBar (like the tabBar) and left/right places your subview within the titleBar.



来源:https://stackoverflow.com/questions/28188005/how-to-use-nstitlebaraccessoryviewcontroller

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