Question

How do you programmatically hide the menu bar in a cocoa app? I would like to make full use of the screen area.

Was it helpful?

Solution

There are two good ways I know of to do this.

1 In Cocoa, you can call the NSMenu class method setMenuBarVisible: to show or hide the menu bar.

As of this writing, the documentation for the NSMenu class does not tell you the following additional information.

The menu bar will only be hidden for the app that calls this method. The Dock will also be hidden at the same time.

(This is true at least in 10.9 and I have not tested any other versions.)

This is useful when you want to use an app in a full screen way where you have a cover window, a borderless window the size of the screen. The nice feature of this (as opposed to playing with LSUIElement settings) is that your app can continue to be in the application switcher cycling, as well as visible in the Dock when other apps are active. This allows users to still activate a full screen app through the Dock or application switcher. That means you can still use your app's Dock menu to access a preferences window for your app or other features. This is incredibly convenient if your app is indeed a full screen cover window that runs at a window level higher than other apps, but you still want to make preferences and the ability to quit your app available, and you want your app's visual functionality available when other apps are active.

2 Another option is via NSApplication's method setPresentationOptions: with the arguments from NSApplicationPresentationOptions enum, such as option NSApplicationPresentationHideMenuBar With this approach be very wary of reading the documentation, although it gives you additional options, and is still app-specific only, you need to know that some of the options are mutually exclusive. There are rules you must follow, or you get nothing but exceptions spewed to the console.

3 There is a 3rd and crappy option. If you have a helper app that is a daemon, you can use it to change your app's LSUIElement state and basically relaunch your app. It's dumb and it takes you out of the app switcher completely, which is great if you really are writing something that should not be there, but that is rare.

OTHER TIPS

There is also the NSView enterFullScreenMode:withOptions: method, although most apps for which that would be appropriate prior to 10.7 should probably use the modern full-screen-window API on 10.7 and later.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top