如何自定义NSToolbar的上下文菜单? [英] How to customize the context menu of NSToolbar?

查看:204
本文介绍了如何自定义NSToolbar的上下文菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从右键单击上下文菜单中删除一些项目,但工具栏不包含用于访问toolbarView的公共API。

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

推荐答案

创建工具栏时,可以访问和修改工具栏上下文菜单, - [awakeFromNib]

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.

这篇关于如何自定义NSToolbar的上下文菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆