Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSTableview Change the highlight colour

I am developing a MAC application and included the tableView. Want to change the Colour of selected row to yellow.

like image 336
Raghav Avatar asked Oct 24 '13 07:10

Raghav


1 Answers

Set this on your table view:

[yourtableview setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone];

And implement the following delegate method of NSTableView as:

- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
    if ([[aTableView selectedRowIndexes] containsIndex:rowIndex]) 
    {
       [aCell setBackgroundColor: [NSColor yellowColor]];   
    } 
    else 
    {
       [aCell setBackgroundColor: [NSColor whiteColor]];
    } 
    [aCell setDrawsBackground:YES];
}  
like image 137
Neha Avatar answered Oct 17 '22 22:10

Neha