2

I subclass my table's column to NStextFieldCell. When I want to change column's color with below given code, color doesn't change. Why?

- (void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
    if(row%2==0)
        [cell setBackgroundColor:[NSColor knobColor]];
    else
        [cell setBackgroundColor:[NSColor lightGrayColor]];

    [cell setDrawsBackground: YES];
}

I use this code in NSTextFieldCell subclass

- (NSRect)titleRectForBounds:(NSRect)theRect 
{
    NSRect titleFrame = [super titleRectForBounds:theRect];
    NSSize titleSize = [[self attributedStringValue] size];
    titleFrame.origin.y = theRect.origin.y + (theRect.size.height - titleSize.height) / 2.0;
    return titleFrame;
}

- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView 
{
    NSRect titleRect = [self titleRectForBounds:cellFrame];
    [[self attributedStringValue] drawInRect:titleRect];
}
Ron
  • 24,175
  • 8
  • 56
  • 97

1 Answers1

1

try:

[cell contentView] setBackgroundColor:[NSColor redColor]];
Luke
  • 11,426
  • 43
  • 60
  • 69
demon9733
  • 1,054
  • 3
  • 13
  • 35