2
votes

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 !!!

2

2 Answers

2
votes

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
votes

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.