swiftmacosnstouchbar

Can I use the system Touch Bar icons in my app?


I am trying to add a "New" button and a "Search" button for my app onto the Touch Bar. In system apps, these are a plus sign and a magnifying glass, respectively. Is there a way to use these system icons on my touch bar buttons, such as in UIBarButtonItems? If not, how can I set a touch bar button's content to be a magnifying glass or plus sign? I am using Swift. Thanks.


Solution

  • Apple provides many system icons that you can use in your app. The Human Interface Guidelines has a nice visual reference of all of the icons available here. These can be referenced in your app by using the associated NSImage.Name constant (also described in the HIG).

    As an example, the new and search images can be gotten using:

    let addImage = NSImage(named: .touchBarAddTemplate)
    let searchImage = NSImage(named: .touchBarSearchTemplate)