Mark
Mark

Reputation: 6977

NSTableView with custom row background: prevent label to turn white on selection

I have a view-based NSTableView that uses custom NSTableRowView instances to draw custom cell backgrounds for normal and for selected rows.

My problem is that labels inside the table rows change to a white color when a row is selected. I assume the text field's cell realized that it is selected and inverted the text color.

However, this does not work well with my custom background/row selection. White text is not visible anymore. Is there a way to prevent the NSTextField from chaining its color with the selection (preferably without subclassing, because I have the same problem with an NSButton)?

Here's a screenshot with the selected row in the middle (white label is hard to see):

selected row in the middle

Upvotes: 3

Views: 1832

Answers (1)

Monolo
Monolo

Reputation: 18253

The best solution is to subclass NSTableCellView and override the setBackgroundStyle: method.

This is described in more detail in @Seth's answer to this question: NSTextField in NSTableCellView .

Upvotes: 4

Related Questions