[英]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.