Customize NSMenu (like Apple's Dock right click Menu)?

只谈情不闲聊 提交于 2019-12-11 03:13:43

问题


Is there any way to customize NSMenu appearances, for example, its transparency, background color or foreground color using public API"S (like Apple's Dock right click Menu) ??

After lots of search i have found some code where they are using private API's for making the menu dark !!!


回答1:


I think you'll have better luck if you just use a custom view which you code to look however you want and to behave like a menu. Apple provides a sample project, CustomMenus, which illustrates that technique. It's a companion to one of the WWDC 2010 session videos, Session 145, "Key Event Handling in Cocoa Applications".




回答2:


Not sure if you decided to go with the solution of drawing the views yourself, but there is a private API that can be used to do this:

    MenuRef m = [[menu _menuImpl] _principalMenuRef];
    if (m) {
        char on = 1;
        SetMenuItemProperty(m, 0, 'dock', 'dark', 1, &on);
    }

There's a Github project that implements this that works basically as a drop-in category on NSMenu and allows darkening with a single property.

This is definitely a bad idea™ since it uses private APIs that may or may not break with future OS updates, but it seems to be the way the dock menu works.



来源:https://stackoverflow.com/questions/15379410/customize-nsmenu-like-apples-dock-right-click-menu

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