Coloring rows in View based NSTableview

后端 未结 4 1522
清酒与你
清酒与你 2021-02-12 17:26

I have a view based nstableview. I want to color entire row based on some condtion for which I have used code below

- (NSTableRowView *)tableView:(NSTableView *)         


        
4条回答
  •  渐次进展
    2021-02-12 18:07

    Finally it worked as below

        - (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
    
    {
            NSView *cellView = (NSView*) [tableView makeViewWithIdentifier:[tableColumn identifier] owner:[tableView delegate]];
            CALayer *viewLayer = [CALayer layer];
            [viewLayer setBackgroundColor:[[NSColor redcolor] CGColor]];
            [cellView setWantsLayer:YES]; 
            [cellView setLayer:viewLayer];
            return cellView;
        }
    

    Please note.. u need to convert nscolor to cgcolor which you can find in https://gist.github.com/707921 or http://forrst.com/posts/CGColor_Additions_for_NSColor-1eW

提交回复
热议问题