Change selection color on view-based NSTableView

前端 未结 13 2061
别跟我提以往
别跟我提以往 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:23

    Some modifications to Jean-Pierre answer

    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 setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleRegular];
    [myRowView setEmphasized:NO];
    }
    

    And to avoid dancing effect of blue then gray set

    [_tableView setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone];
    

提交回复
热议问题