0

I subclassed NSTableRowView in view-based NSTableView to change the selection color to a lighter blue instead of the default one.

Unfortunately when I select the row the color of the labels and textfields inside my custom cell turns white and it's not readable.

How can I prevent text from changing color on selection?

Solution Found:

All I had to do is to implement -setBackgroundStyle: in my custom NSTableCellView and there call the setBackgroundStyle:NSBackgroundStyleLight on the NSCell of all the controls I want to keep dark on selection.

Keith Smiley
  • 61,481
  • 12
  • 97
  • 110
Jacopo
  • 1,031
  • 2
  • 12
  • 25

3 Answers3

1

You'll need to make a custom NSCell.

sgress454
  • 24,870
  • 4
  • 74
  • 92
  • Thanks for the link. It seems to go in the right direction although I have to admit I don't fully understand how to apply that method to my view-based table view. I'm already using a custom subclass of NSTableCellView. – Jacopo Jul 24 '12 at 08:02
1

OK I figured it out.

All I had to do is to implement -setBackgroundStyle: in my custom NSTableCellView and there call the setBackgroundStyle:NSBackgroundStyleLight on the NSCell of all the controls I want to keep dark on selection.

Jacopo
  • 1,031
  • 2
  • 12
  • 25
  • 1
    Glad to see you figured it out--you should edit your original question to show the solution you found, so that the next person with this issue can find the answer right off the bat! – sgress454 Jul 24 '12 at 21:06
0

How did you change the selection color? This sounds like it could have been caused by you adding a subview or sublayer (perhaps to cell.selectedBackgroundView?) on top of the existing layers. If you have any insertSublayer or subView calls, make sure you are doing them atIndex:0.

Seth Nelson
  • 2,598
  • 4
  • 22
  • 29