我将表的列子类化为NStextFieldCell
. 当我想用下面给定的代码更改列的颜色时,颜色不会改变。为什么?
- (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];
}
NSTextFieldCell
我在子类中使用此代码
- (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];
}