objective-cswiftmacosnstouchbar

Touch Bar, how to add a scrollable list of buttons?


I’d like to show a scrollable list of buttons in my app’s Touch Bar, similar to how Safari shows favourites when typing an address.

A scroll view doesn’t seem to be one of the standard TouchBar controls. Which controls do you use for this?


Solution

  • As you probably know, you add NSTouchBarItems to a TouchBar instance in order to add items to a Touch Bar.

    In order to add a scrollable list, create an instance of NSScrubber. Once that's set up, you'll need to add that NSScrubber to a custom instance of NSCustomTouchBarItem, most likely to the view property. Then, you can add that item to the Touch Bar. Be sure to read the linked documentation.