문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top