0

我有一个 NSComboBox,我希望它显示光标所在的字体名称。我有当前的代码:

- (void)textDidChange:(NSNotification *)notification {
    [self.fontBox setStringValue:[self.doc.textStorage attribute:NSFontAttributeName atIndex:(self.doc.selectedRange.location - 1) effectiveRange:nil]];

} 

它将组合框的标题设置为字体,但我得到类似的东西:"ArialMT 12.00 pt. P [] (0x1001a95b0) fobj=0x1006511c0, spc=3.33"我只想得到 Arial、Times New Roman 或 Helvetica,而不是那个长字符串。我怎样才能做到这一点?

4

1 回答 1

0

使用NSFontdisplayName属性。

NSFont *font = [self.doc.textStorage attribute:NSFontAttributeName atIndex:(self.doc.selectedRange.location - 1) effectiveRange:nil];
[self.fontBox setStringValue:font.displayName];
于 2015-02-10T03:22:14.507 回答