macoscocoansfontpanelnsfontmanager

How can I get NSFontManager selected font?


I can't get selected font in NSFontManager. What I need:

1) I need to get selected font title, size, color?

I am calling NSFontManager with button like this:

[[NSFontManager sharedFontManager] orderFrontFontPanel:self];

It's opening but I don't know how to get selected font. As string for example: Verdana.

I have read apple's docs but I can't understand how to get what font is selected. I'm not changing or converting any fonts. I just need to get what font was selected.


Solution

  • NSString *selectedFontName = [[[NSFontManager sharedFontManager] selectedFont] displayName];
    

    (depending on your intended use, you may want to use fontName instead of displayName.)