Cocoa: Tab view with toolbar icons for switching t

2019-02-07 19:03发布

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?

2条回答
太酷不给撩
2楼-- · 2019-02-07 19:46

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 2013 Session 212: Storyboards and Controllers on OS X walks through this scenario starting around 10m45s.

查看更多
我只想做你的唯一
3楼-- · 2019-02-07 20:03

BWToolkit has code that does what you want.

If you fancy implementing it yourself, you could take a look at the code and see what it's doing. Hint: NSToolbar's delegate protocol has a toolbarSelectableItemIdentifiers: method, and you can create a tab view without showing tabs, switching between tabs programmatically.

查看更多
登录 后发表回答