[英]How do I extract the font name from a NSFontAttributeName?
我有一个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"
组合框的标题设置为字体,但是我得到的东西类似于: "ArialMT 12.00 pt. P [] (0x1001a95b0) fobj=0x1006511c0, spc=3.33"
而我只想获取Arial或Times New Roman,或Helvetica,不是那么长。 我怎样才能做到这一点?
使用NSFont
的displayName
属性。
NSFont *font = [self.doc.textStorage attribute:NSFontAttributeName atIndex:(self.doc.selectedRange.location - 1) effectiveRange:nil];
[self.fontBox setStringValue:font.displayName];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.