Skip to content

Instantly share code, notes, and snippets.

@n3tr
Last active October 30, 2016 15:34
Show Gist options
  • Save n3tr/e8a7762df56b86e81c8587e801d7e023 to your computer and use it in GitHub Desktop.
Save n3tr/e8a7762df56b86e81c8587e801d7e023 to your computer and use it in GitHub Desktop.
extension WindowController: NSTouchBarDelegate {
func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItemIdentifier) -> NSTouchBarItem? {
switch identifier {
case NSTouchBarItemIdentifier.label:
// Create custom touch bar Item
let custom = NSCustomTouchBarItem(identifier: identifier)
custom.customizationLabel = "Label Title"
// Create label as NSTextField
let label = NSTextField(labelWithString: "Hello, TouchBar")
label.textColor = NSColor.green
// Assign custom item's view
custom.view = label
return custom
default:
return nil
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment