ビューベースの NSTableView には、NSTableCellView のサブクラスがあります。
選択した行の cellView のテキストの色を変更したい。
class CellView: NSTableCellView {
override var backgroundStyle: NSBackgroundStyle {
set {
super.backgroundStyle = newValue
self.udpateSelectionHighlight()
}
get {
return super.backgroundStyle;
}
}
func udpateSelectionHighlight() {
if ( self.backgroundStyle == NSBackgroundStyle.Dark ) {
self.textField?.textColor = NSColor.whiteColor()
} else if( self.backgroundStyle == NSBackgroundStyle.Light ) {
self.textField?.textColor = NSColor.blackColor()
}
}
}
問題は、すべての cellViews が NSBackgroundStyle.Light で設定されていることです。
私の選択は、NSTableRowView のサブクラスでカスタム描画されます。
class RowView: NSTableRowView {
override func drawSelectionInRect(dirtyRect: NSRect) {
if ( self.selectionHighlightStyle != NSTableViewSelectionHighlightStyle.None ) {
var selectionRect = NSInsetRect(self.bounds, 0, 2.5)
NSColor( fromHexString: "d1d1d1" ).setFill()
var selectionPath = NSBezierPath(
roundedRect: selectionRect,
xRadius: 10,
yRadius: 60
)
// ...
selectionPath.fill()
}
}
// ...
}
選択した行の cellView の backgroundStyle プロパティが Dark に設定されていないのはなぜですか?
ありがとう。