2
votes

If I run this code (on the iPhone):

NSArray *names = [UIFont familyNames];
NSLog(@"Font FamilyNames");
for (NSString *name in names) {
    NSLog(@"Font Family:  %@",name);
    NSArray *fontFaces = [UIFont fontNamesForFamilyName:name];
    for (NSString *fname in fontFaces) {
        NSLog(@"              %@",fname);
    }
}

I get this output (abridged):

...
Font Family:  Georgia
          Georgia-BoldItalic
          Georgia-Bold
          Georgia-Italic
          Georgia
Font Family:  Helvetica Neue
          HelveticaNeue-BoldItalic
          HelveticaNeue-Light
          HelveticaNeue-Italic
          HelveticaNeue-UltraLightItalic
          HelveticaNeue-CondensedBold
          HelveticaNeue-MediumItalic
          HelveticaNeue-Thin
          HelveticaNeue-Medium
          HelveticaNeue-ThinItalic
          HelveticaNeue-LightItalic
          HelveticaNeue-UltraLight
          HelveticaNeue-Bold
          HelveticaNeue
          HelveticaNeue-CondensedBlack
Font Family:  Gill Sans
          GillSans
          GillSans-Italic
...

You can see that each font family has various fonts, but the font names are anything but user-friendly. For example, TextEdit presents them in a much better way:

TextEdit presenting font names in a respectable way

How can I in a stable way (meaning it works on all fonts, even fonts not yet available on iOS) get the names for each font like TextEdit?

The only thing that comes to mind is to parse each font face name, turning HelveticaNeue-CondensedBold into Condensed Bold and HelveticaNeue-UltraLightItalic into Ultra Light Italic. However, you'll notice that TextEdit presents HelveticaNeue-UltraLightItalic as UltraLight Italic, not Ultra Light Italic and I'm not sure this method works for all fonts...

Examples of fonts that would not work well with my idea:

Font Family:  Bodoni 72
          BodoniSvtyTwoITCTT-Book
          BodoniSvtyTwoITCTT-Bold
          BodoniSvtyTwoITCTT-BookIta

(Bodoni 72 != BodoniSvtyTwoITCTT)

Font Family:  Times New Roman
          TimesNewRomanPS-BoldItalicMT
          TimesNewRomanPSMT
          TimesNewRomanPS-BoldMT
          TimesNewRomanPS-ItalicMT

(Times New Roman != TimesNewRomanPS and what's up with that MT?)

Other problem with it: No font face name contains Regular, but that is what users expect to see in the options (see the TextEdit screenshot).

1
Hi Alex, Did you ever find a good solution for this problem? I have the same issue, and like you mention parsing has it's limits.Freek Sanders
@FreekSanders unfortunately, no, I had to leave the names as-is, without parsing...Alex
thanks for the quick response. I'm also leaving the names as-is.Freek Sanders

1 Answers

0
votes

HelveticaNeue (Without - Anything)= Regular.

MT = Monotype

See: http://www.fonts.com/support/faq/lt-mt-ef-abbreviations

How to use fonts that are not available on iOS as default?

  1. You will need to config your PList
  2. Drag the font files into your resource folder
  3. Then you can use the new custom font like below code:-

     [self.activateBtn.titleLabel setFont:
                  [UIFont fontWithName:@"ProximaNova-Regular" size:15]];
    

For more information, you may visit: Use custom fonts in iPhone App