MacOS 10.12+, Xcode 8+, Swift 3:
I'd like to programmatically customize the font and drawing of an NSTableView header. I know there are older questions about this, but I couldn't find anything that works today.
For example, I tried to subclass NSTableHeaderCell to set a custom font:
class MyHeaderCell: NSTableHeaderCell {
override func drawInterior(withFrame cellFrame: NSRect, in controlView: NSView) {
NSLog("MyHeaderCell is drawing")
font = NSFont.boldSystemFont(ofSize: 12)
super.drawInterior(withFrame: cellFrame, in: controlView)
}
}
And then use that subclass in my table view:
tableColumn.headerCell = MyHeaderCell()
I see the message "MyHeaderCell is drawing" in the console, but the font of the table header doesn't change.
Thanks to comments from @HeinrichGiesen and @Willeke, I got it working. I'm posting it here in case it helps someone down the line. Note that my way of customizing the background color isn't that flexible. I'm really just tinting the default drawing. It's good enough for my purposes.