Objective c NSTableview更改高光颜色
我正在开发一个MAC应用程序,包括tableView。Objective c NSTableview更改高光颜色,objective-c,macos,cocoa,nstableview,Objective C,Macos,Cocoa,Nstableview,我正在开发一个MAC应用程序,包括tableView。 要将所选行的颜色更改为黄色。在表视图中设置此选项: [yourtableview setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone]; 并将NSTableView的以下委托方法实现为: - (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(N
要将所选行的颜色更改为黄色。在表视图中设置此选项:
[yourtableview setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone];
并将NSTableView的以下委托方法实现为:
- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
if ([[aTableView selectedRowIndexes] containsIndex:rowIndex])
{
[aCell setBackgroundColor: [NSColor yellowColor]];
}
else
{
[aCell setBackgroundColor: [NSColor whiteColor]];
}
[aCell setDrawsBackground:YES];
}
如果只想高亮显示列的单个单元格,请执行如下操作:-
- (void)tableView:(NSTableView *)tableView
willDisplayCell:(id)cell
forTableColumn:(NSTableColumn *)tableColumn
row:(NSInteger)row
{
if ([[tableColumn identifier] isEqualToString:@"yourColumm"])
{
[cell setBackgroundColor:[NSColor yelloColor]];
}
}
这可能会有帮助-谢谢你。。。我会试试这个…:)假设你说的是一个基于单元格的表,这与上一个答案的原因不同,除非你的单元格恰好没有任何填充(甚至可能没有填充)。要更改行高光,请覆盖表的HighlightSelectionCliprect:方法并自己绘制背景色,如下所示:所选行中单元格的背景完全被行高光覆盖,因此,据我所知,设置单元格的背景色根本不会更改单元格的外观。