How to customize the context menu of NSToolbar?

前端 未结 1 1045
再見小時候
再見小時候 2021-01-07 13:39

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

1条回答
  •  时光说笑
    2021-01-07 14:06

    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.

    0 讨论(0)
提交回复
热议问题