Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a two-row toolbar like in Mail.app and Xcode?

I'm trying to add a "second row" after my NSToolbar in my app, that remains part of the title bar. As an example, Mail has a thin gray divider line below the NSToolbar with some extras items below that. Very specifically, when the window is put into fullscreen mode, that second "row" stays attached to the title bar as it slides down under 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 textured and placing my second row controls directly in the content view of the window. While this mostly looks correct in windowed mode, those controls of course won't appear attached to the toolbar when it slides down in fullscreen mode. So how can I achieve the same behavior that Mail and Xcode do? I've looked at a lot of toolbar customization code but none of them really cover this specific case.

enter image description hereenter image description here

like image 318
Jake Petroules Avatar asked Dec 04 '12 21:12

Jake Petroules


2 Answers

fullScreenAccessoryView is deprecated in macOS 10.10

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

For example:

NSTitlebarAccessoryViewController *accessoryViewController = [[NSStoryboard storyboardWithName:@"Main" bundle:nil] instantiateControllerWithIdentifier:@"AccessoryViewController"];
[self.mainWindowController.window addTitlebarAccessoryViewController:accessoryViewController];
like image 67
Josh Avatar answered Jan 01 '23 15:01

Josh


What I needed to do was call [NSToolbar setFullScreenAccessoryView:] on the view below my toolbar. This results in the behavior I was aiming for. See the NSToolbar documentation for this method.

like image 41
Jake Petroules Avatar answered Jan 01 '23 15:01

Jake Petroules