gpt4 book ai didi

objective-c - 无法更改我子类化的列的颜色

转载 作者:行者123 更新时间:2023-12-03 16:43:23 25 4
gpt4 key购买 nike

我将表的列子类为 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];
}

最佳答案

尝试:

[cell contentView] setBackgroundColor:[NSColor redColor]];

关于objective-c - 无法更改我子类化的列的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10271199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com