macOS NSTabViewController centered tab icons
I have a macOS app I have created. And I have a Preferences window built using a swift & storyboard with a tabless Toolbar styled NSTabViewController.
I see no way to override the positioning of the tab icons though - they default to the left side of the window. Is it possible?
Subclass NSTabViewController
and override func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier]
. Add a flexibleSpace
toolbar item at both sides.
following Willeke's tip, I came up with this override in my NSTabViewController
subclass:
override func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
super.toolbarDefaultItemIdentifiers(toolbar)
var arr = Array<NSToolbarItem.Identifier>()
for item in self.tabViewItems {
if let identifier = item.identifier {
arr.append(NSToolbarItem.Identifier.init(identifier as! String))
}
}
//insert flexible spaces at first and last index
arr.insert(NSToolbarItem.Identifier.flexibleSpace, at: 0)
arr.append(NSToolbarItem.Identifier.flexibleSpace)
return arr
}