3
뷰 기반 NSTableView에서 NSTableCellView의 하위 클래스가 있습니다.왜 NSTableCellView.backgroundStyle이 선택된 행에 대해 NSBackgroundStyle.Dark로 설정되지 않았습니까?
선택한 행의 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()
}
}
}
문제는 모든 cellView가 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 속성이 어둡게 설정되어 있지 않습니까?
감사합니다.
class CellView: NSTableCellView {
override var backgroundStyle: NSBackgroundStyle {
set {
if let rowView = self.superview as? NSTableRowView {
super.backgroundStyle = rowView.selected ? NSBackgroundStyle.Dark : NSBackgroundStyle.Light
} else {
super.backgroundStyle = newValue
}
self.udpateSelectionHighlight()
}
get {
return super.backgroundStyle;
}
}
func udpateSelectionHighlight() {
if (self.backgroundStyle == NSBackgroundStyle.Dark) {
self.textField?.textColor = NSColor.whiteColor()
} else {
self.textField?.textColor = NSColor.blackColor()
}
}
}
: