我尝试在没有任何突出显示的情况下在 NSTableView 中制作粗体行选择样式
我关闭了突出显示:
[myTable setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone];
但是,我在选定行中使文本变为粗体时遇到了一些麻烦。正如我所建议的,我需要更改 NSTableView 源的属性:
- (void) tableViewSelectionDidChange: (NSNotification *) notification
{
NSDictionary *boldFont = [NSDictionary dictionaryWithObject:[NSFont boldSystemFontOfSize:13.0]
forKey:NSFontAttributeName];
NSDictionary *normalFont = [NSDictionary dictionaryWithObject:[NSFont systemFontOfSize:13.0]
forKey:NSFontAttributeName];
for(MyClass *obj in tableSourceList)
obj.name = [[NSMutableAttributedString alloc]
initWithString:obj.name
attributes: normalFont];
long row = [myTable selectedRow];
MyClass objectAtSelectedRow = [tableSourceList objectAtIndex: row];
objectAtSelectedRow.name = [[NSMutableAttributedString alloc]
initWithString:dr.dreamname
attributes: boldFont];
[tableSourceList replaceObjectAtIndex:row withObject:objectAtSelectedRow];
}
不幸的是,没有效果。
选择时如何使行中的文本变为粗体?