0

I have a NSComboBox and I want it to display the font name where the cursor is. I have the current code :

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

} 

Which sets the title of the combo box to the font but I get something similar to: "ArialMT 12.00 pt. P [] (0x1001a95b0) fobj=0x1006511c0, spc=3.33" And I just want to get Arial, or Times New Roman, or Helvetica, not that long string. How can I do this?

1 Answers1

0

Use NSFont's displayName property.

NSFont *font = [self.doc.textStorage attribute:NSFontAttributeName atIndex:(self.doc.selectedRange.location - 1) effectiveRange:nil];
[self.fontBox setStringValue:font.displayName];
bluedome
  • 2,449
  • 1
  • 22
  • 17
  • I would give you $500 if I could. I am such a n00b sometimes. All these methods and variables and everything is no confusing to me! –  Feb 10 '15 at 04:20