cocoamacostoolbarnstabview

Cocoa: Tab view with toolbar icons for switching tabs


Various Preferences dialogs (Safari, Mail, Xcode4, and any that uses NSPreferences) and Xcode4's Organizer use something reminiscent of a tab view -- except that is uses toolbar buttons for switching between tabs. These buttons are "pressed".

What is the best way to implement such a tab view? Is there a documented public API for implementing them?


Solution

  • Since Mac OS X 10.10 (Yosemite), the easiest way to do this is to lay out your preferences dialog window in a storyboard using an NSTabViewController, and set its tabStyle to NSTabViewControllerTabStyleToolbar.

    WWDC 2014 Session 212: Storyboards and Controllers on OS X walks through this scenario starting around 10m45s.


    Update 2020-01-14: Apple, in its infinite wisdumb, has apparently removed that video.