I have an NSTableView (view Based) who show info's from an NSarrayController. All connections are made from IB. Everything works fine, but blue selection color doesn't look ok with my design idea, so I want to change this color with my own color, but until now I failed.
class MyTable: NSTableView, NSTableViewDelegate {
override func drawBackgroundInClipRect(clipRect: NSRect) {
if self.isRowSelected( self.selectedRow ){
//NSColor.brownColor().colorWithAlphaComponent(0.9).setFill()
// NSBezierPath.fillRect(clipRect)
println("selected")
}
}
}
My real problem is that: I have no idea where should I start, what to subclass, NSTableView , NSTableCellView etc.
Recent I discovered a method to do that which say I should subclass NSTableRowView, and override drawSelectionInRect function. I've did that, but in IB i don't have an NSTableRowView Object.
Thanks.
Swift 4 version of @Prontto 's excellent answer.
class MyRowView: NSTableRowView {
override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)
if isSelected == true {
NSColor.green.set()
dirtyRect.fill()
}
}
}
.
// In your NSTableViewDelegate
func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
return MyRowView()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With