2

テーブルの列を にサブクラス化します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];
}
4

1 に答える 1

1

試す:

[cell contentView] setBackgroundColor:[NSColor redColor]];
于 2012-04-22T19:21:23.813 に答える