gpt4 book ai didi

objective-c - 如何在选择 NSOutlineView 的行时设置背景颜色

转载 作者:搜寻专家 更新时间:2023-10-30 20:25:23 24 4
gpt4 key购买 nike

我遇到了一个大问题,但无法解决。

我有一个 NSOutlineView,它包含一个绑定(bind)到 arrayControllerNSButtonCell,它正在设置它的 Title 并根据一些值,通过代码在单元格背景中设置图像。

图像是使用这些代码设置的

[cell setImage:[NSImage imageNamed:@"sbWarn.png"]];
[cell setImagePosition:NSImageOverlaps];
[cell setBackgroundColor:[NSColor clearColor]];

问题是当我选择一行时,所选行显示黑色背景。我尝试了所有可能的方法,比如将背景设置为 clearColor 等。

我怎样才能让它看起来好看。

最佳答案

这种方法应该有效。它来自内存,所以不能保证,但一个快速的模型似乎可以提供您正在寻找的结果:

// Outline view delegate

-(void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item {

NSUInteger rowNo = [outlineView rowForItem:item];

NSColor *backgroundColor;
if ( [[outlineView selectedRowIndexes] containsIndex:rowNo] ) {
backgroundColor = // Highlighted color;
}
else {
backgroundColor = // Normal background color;
}

[cell setBackgroundColor: backgroundColor];
}

在您的情况下,您当然只会在带有按钮单元格的列上应用单元格背景色。

这是在 outlineView:dataCellForTableColumn:item: 中创建的按钮单元格。

NSButtonCell *cell = [[NSButtonCell alloc] init];

[cell setBezelStyle:NSRegularSquareBezelStyle];
[cell setButtonType:NSToggleButton];
[cell setBordered:NO];
[cell setTitle:@""];
[cell setImage:[NSImage imageNamed:@"green.png"]];
[cell setAlternateImage:[NSImage imageNamed:@"red.png"]];
[cell setImagePosition:NSImageOverlaps];

关于objective-c - 如何在选择 NSOutlineView 的行时设置背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16012187/

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