Here is a solution i found:
Remove the highlight style of your tableView like this:
tableView.selectionHighlightStyle = .none
Set different background in tableViewSelectionDidChange method like this:
func tableViewSelectionDidChange(_ notification: Notification) {
guard let tableView = notification.object as? NSTableView else { return }
guard tableView.selectedRow >= 0 else {
for i in 0..<tableView.numberOfRows {
guard let rowView = tableView.rowView(atRow: i, makeIfNecessary: false) else {
return
}
rowView.backgroundColor = .clear
}
return
}
guard let rowView = tableView.rowView(atRow: tableView.selectedRow, makeIfNecessary: false) else {
return
}
rowView.backgroundColor = .red.withAlphaComponent(0.1)
}
The full code can be found here.
Topic:
UI Frameworks
SubTopic:
AppKit
Tags: