How can I get a two-line toolbar, for example, in Mail.app and Xcode?

I am trying to add a “second line” after my NSToolbar in my application, which remains part of the title bar. For example, Mail has a thin gray dividing line under NSToolbar with some additional elements below. In particular, when a window is placed in full-screen mode, this second “line” remains attached to the title bar when it slides down in the system menu bar. Xcode has a similar story.

enter image description hereenter image description hereenter image description hereenter image description here

I tried setting my NSWindow to texturing and placing second-line controls directly in the window's content window. Although this basically looks right in windowed mode, these controls, of course, will not appear on the toolbar when they slide in full screen mode. So, how can I achieve the same behavior as Mail and Xcode? I looked through a lot of toolbar customization code, but not one of them covers this particular case.

enter image description hereenter image description here

+4
source share
3 answers

I needed to make a call to [NSToolbar setFullScreenAccessoryView:] in the view below my toolbar. This leads to the behavior I was striving for. For this method, see the NSToolbar documentation .

+3
source

The first one is the usual toolbar. For the second toolbar, you can create a separate view of the desired height and add it to the main landing window.

0
source

fullScreenAccessoryView deprecated on macOS 10.10

To do this in recent versions of macOS, use the addTitlebarAccessoryViewController method on your NSWindow and go to a subclass of NSTitlebarAccessoryViewController .

For instance:

 NSTitlebarAccessoryViewController *accessoryViewController = [[NSStoryboard storyboardWithName:@"Main" bundle:nil] instantiateControllerWithIdentifier:@"AccessoryViewController"]; [self.mainWindowController.window addTitlebarAccessoryViewController:accessoryViewController]; 
0
source

All Articles