由于使用的是基于视图的NSTableView,因此可以将NSTableRowView子类化,将其提供给表委托方法- (NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger)row;
,然后在行视图类中自定义选择。
import Foundation
import Cocoa
class BMTableRowView : NSTableRowView {
override func drawSelection(in dirtyRect: NSRect) {
if self.selectionHighlightStyle != .none {
let selectionRect = bounds.insetBy(dx: 0, dy: 0)
NSColor.color(withRGB: 0x3578f6)!.setFill()
let selectionPath = NSBezierPath(roundedRect: selectionRect, xRadius: 6, yRadius: 6)
selectionPath.fill()
}
}
}
使用:
func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
let rowView = BMTableRowView()
return rowView
}