How to customize the context menu of NSToolbar?

﹥>﹥吖頭↗ 提交于 2019-12-01 12:48:25

问题


I need to remove some items from right-click context menu, but the toolbar does not contain a public API to access 'toolbarView'.

Is it possible to customize the menu without using private API?


回答1:


You can access and modify a toolbar contextual menu when the toolbar is created, i.e. in -[awakeFromNib]:

- (NSMenu *)toolbarMenuInWindow:(NSWindow *)window
{
    NSView *contentView = window.contentView;
    NSView *toolbarView = contentView.superview.subviews.lastObject;
    NSMenu *toolbarMenu = toolbarView.menu;
    return toolbarMenu;
}

Now you can directly edit menu items and hide or disable them.



来源:https://stackoverflow.com/questions/8413111/how-to-customize-the-context-menu-of-nstoolbar

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