Change selection color on view-based NSTableView

前端 未结 13 2114
别跟我提以往
别跟我提以往 2020-12-07 19:11

Standard highlighting color in OS X applications is blue.

Is it possible to change it to another color, e.g. gray?

Note that I am using the new view-based

13条回答
  •  余生分开走
    2020-12-07 19:29

    Use the following code in response to the NSTableViewDelegate protocol tableViewSelectionDidChange:

    Get the NSTableRowView for the selected row and call the method setEmphasized on it. When setEmphasized is set to YES you get the blue highlight, when NO you get the gray highlight.

    -(void)tableViewSelectionDidChange:(NSNotification *)aNotification {
    
         NSInteger selectedRow = [myTableView selectedRow];
         NSTableRowView *myRowView = [myTableView rowViewAtRow:selectedRow makeIfNecessary:NO];
         [myRowView setEmphasized:NO];
    }
    

提交回复
热议问题