4
我将NSAttributedString插入到NSTableView中,并根据它的内容将属性添加到其样式字典中。NSAttributedString删除线不会绘制整个文本的长度
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex {
NSAttributedString *theValue;
NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];
[attributes setObject:[NSFont systemFontOfSize:11] forKey:NSFontAttributeName];
currentObject = [ticketsDataSource objectAtIndex:rowIndex];
if ([[currentObject valueForKey:aTableColumn.identifier] isKindOfClass:([NSString class])]) {
NSString *currentValue = [currentObject valueForKey:aTableColumn.identifier];
if ([currentValue isEqualToString:@"resolved"]) {
[attributes setObject:[NSColor colorWithCalibratedRed:0.344 green:0.619 blue:0.000 alpha:1.000] forKey:NSForegroundColorAttributeName];
}
if ([previousValue isEqualToString:@"resolved"]) {
[attributes setObject:[NSNumber numberWithInteger:NSUnderlinePatternSolid | NSUnderlineStyleSingle] forKey:NSStrikethroughStyleAttributeName];
}
theValue = [[NSAttributedString alloc] initWithString:currentValue attributes:attributes];
previousValue = currentValue;
}
正如你所看到的,基本上会发生什么是当它写了一个名为“解决”字符串,它知道第二天列,这是标题列,得到了删除线。它工作得很好,但无论出于何种原因,删除线不会覆盖整个文本!
这里是一个形象:
这到底是怎么回事?