Swift 4, macOS 10.13
I have an NSOutlineView
and I'm trying to customize the look of each row when the user clicks it.
I have a view-based NSTableCellView
subclass that I'm using for the cell. When I override backgroundStyle
, the icon change works perfectly. But the text color is doing something weird.
Here's a video to demonstrate: http://d.pr/v/suTD8B
Here's my code:
class MenuItemCell: NSTableCellView{
@IBOutlet weak var label: NSTextField!
@IBOutlet weak var icon: NSImageView!
//Customizes the selected state of menu row
override var backgroundStyle: NSView.BackgroundStyle {
set{
if let rowView = self.superview as? NSTableRowView {
super.backgroundStyle = rowView.isSelected ? .dark : .light
}
if self.backgroundStyle == .dark {
label.textColor = NSColor.white
icon.image = NSImage(named: NSImage.Name(rawValue: "menu-project-selected"))
}else{
label.textColor = NSColor.menuTextColor
icon.image = NSImage(named: NSImage.Name(rawValue: "menu-project"))
}
}
get{ return super.backgroundStyle }
}
}
Any idea what's wrong? I've been searching for hours and can't figure it out.