这种方法应该有效。它来自记忆,所以不能保证,但一个快速的模型似乎给出了你正在寻找的结果:
// 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];