Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change NSTextField text color on row selection?

For cocoa, I have an NSTableView set to be view based. When a row is selected, the text fields change their color to white. How do I keep it black?

I should also note that the Highlight is set to Source List (it does the same thing on Regular). Highlight Setting

Unselected row Unselected

Selected Row Selected Row

I was hoping for something similar to the state config for iOS:

enter image description here

This was suggested in WWDC 2011 Session 120 but it's a bit delayed so I'm not going to use it. It may work for someone else though.

- (void)tableViewSelectionDidChange:(NSNotification *)notification
{
    [tableView enumerateAvailableRowViewsUsingBlock:^(NSTableRowView *rowView, NSInteger row){
        NSTableCellView *cellView = [rowView viewAtColumn:0];
        if(rowView.selected){
            cellView.textField.font = [NSFont boldSystemFontOfSize:14];
        }else{
            cellView.textField.font = [NSFont systemFontOfSize:14];
        }
    }];
}
like image 500
joels Avatar asked Jun 29 '12 20:06

joels


1 Answers

There is no need for custom code to accomplish that.

Just set the color of the label to "label color" in Interface Builder. The automatic white/black thing only works if the label has the "Control Text Color" set and is in an NSTableCellView.

like image 158
paxos Avatar answered Nov 03 '22 18:11

paxos