Post not yet marked as solved
Post marked as unsolved with 7 replies, 1,669 views
I am trying to understand how an NSTextField reacts to changes of its cell's backgroundStyle.The reason is that I want to use the automatic handling of the text color be used when I set the backgroundStyle of the text field that's inside a table cell.From what I have gathered so far, the textfield's cell has a backgroundStyle property and when this is set, and the textColor is `labelColor` (or any of the other control colors) the text color should be automatically updated to be fitting for the backgroundStyle.Given a tableView with a custom row class and a custom cell:class RowView: NSTableRowView {
override func drawSelection(in dirtyRect: NSRect) {
if isSelected {
NSColor.white.set()
var rects: UnsafePointer<NSRect>? = nil
var count: Int = 0
self.getRectsBeingDrawn(&rects, count: &count)
for i in 0..<count {
let rect = NSIntersectionRect(bounds, rects![i])
__NSRectFillUsingOperation(rect, NSCompositingOperation.sourceOver)
}
}
}
override var interiorBackgroundStyle: NSView.BackgroundStyle {
return isSelected ? .light : .dark
}
}andclass CustomCellView: NSTableCellView {
@IBOutlet weak var label: NSTextField!
override var backgroundStyle: NSView.BackgroundStyle {
didSet {
Swift.print("Style set to \(backgroundStyle == .light ? "light" : "dark")")
Swift.print("Label Style set to \(label.cell!.backgroundStyle == .light ? "light" : "dark")")
}
}
}I would expect the label to be drawn in black, when I select the row.I can see that the backgroundStyle is forwarded correctly when I select the row, but the label doesn't change color at all. In fact, being seemingly blended with my white selection, the label disappears entirely.Why is the label color not changing?P.S.: I know that I can manually set the label's color based on the background style of the cell. That's not what I am asking. I want to use the convenience of the `controlTextColor`s or at least understand why they are not working in this case. (They do seem to work if I don't draw my custom selection in the row and use the standard blue selection)