I've been trying to provide NSOutlineView with custom disclosure button.
Here is a simple NSButton subclass for that purpose:
Then, in my NSOutlineView subclass, I do this:
It basically sets two SF Symbols images to image and alternateImage respectively.
My problem is that there are only three NSButton.ButtonType values that work with button auto-rotate: .toggle, .switch, .radio, but none of them respect the contentTintColor -- the buttons are always gray.
Here is a simple NSButton subclass for that purpose:
Code Block Swift final class AltDisclosureButton: NSButton { override init(frame frameRect: NSRect) { super.init(frame: frameRect) setButtonType(.toggle) isBordered = false } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } }
Then, in my NSOutlineView subclass, I do this:
Code Block Swift override func makeView(withIdentifier identifier: NSUserInterfaceItemIdentifier, owner: Any?) -> NSView? { var view = super.makeView(withIdentifier: identifier, owner: owner) if identifier == NSOutlineView.showHideButtonIdentifier, let button = view as? NSButton { let customButton = AltDisclosureButton(frame: .zero) customButton.target = button.target customButton.action = button.action customButton.identifier = identifier let image = NSImage(systemSymbolName: "chevron.right.circle.fill", accessibilityDescription: "disclosure_indicator_button")! customButton.image = image let altImage = NSImage(systemSymbolName: "chevron.down.circle.fill", accessibilityDescription: "disclosure_indicator_button_down")! customButton.alternateImage = altImage customButton.symbolConfiguration = NSImage.SymbolConfiguration(pointSize: 16, weight: .medium) customButton.contentTintColor = NSColor.controlAccentColor view = customButton } return view }
It basically sets two SF Symbols images to image and alternateImage respectively.
My problem is that there are only three NSButton.ButtonType values that work with button auto-rotate: .toggle, .switch, .radio, but none of them respect the contentTintColor -- the buttons are always gray.