I'm using a view-based table view and don't want it to draw NSTextFields with white text color when it is selected. I was not able to find a working solution. So any help is very appreciated.
Here is my problem:
I want the "Selection is white" text also be drawn in the default text color.
So far I figured out that
tableView:viewForTableColumn:item:
does not really helpNSTextField
color to a custom color, which is something different than the control default color, will prevent from drawing in white but it still looses font style (bold, italic, etc).NSTableView
's selectionHighlightStyle
attribute to NSTableViewSelectionHighlightStyleNone
does the trick but it will not redraw NSTableRowView
. Also the select style is not what I want. I want the first click to select the row and the second click to edit the text field. When you use NSTableViewSelectionHighlightStyleNone
your first click starts editing the text field.I couldn't figure out 'how' the text field gets the white color. I have overridden setTextColor:
and realized that it is never called when selection is changed. So I guess an NSAttributedString is built somewhere inside the NSTableView drawing/selecting routine.
Any help is very much appreciated.
I found the answer. I had to subclass NSTableCellView
and override setBackgroundStyle:
. That's all!
- (void)setBackgroundStyle:(NSBackgroundStyle)backgroundStyle {
[super setBackgroundStyle: NSBackgroundStyleLight];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With