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];
}