2

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).

Alex
  • 5,009
  • 3
  • 39
  • 73

1 Answers1

0

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

Community
  • 1
  • 1
Ricky
  • 10,485
  • 6
  • 36
  • 49
  • I don't actually *need* to embed custom fonts in my app. All I want to do is have a user-friendly name for each font face that works with any font. And about that, you're suggesting that I parse the string? That doesn't sound very reliable... – Alex May 11 '14 at 13:24
  • 1
    Are you working on an app that allows the users to choose font? If it is, I think parse the string is the only way. And may be limit the font types for users. For us, who are using custom fonts, I think no matter how user not friendly is the font name does not matter for us as the users will not see the name. – Ricky May 11 '14 at 13:30
  • `Are you working on an app that allows the users to choose font?`: Yes, I am. Thanks, I'll try the parsing idea... – Alex May 11 '14 at 13:37
  • Just sharing what I know. No problem. ;) – Ricky May 11 '14 at 13:40
  • You can likely get a font descriptor and extract at least some attributes that have semantic meaning, such as bold and italic. Sorry, I'm on mobile, or I would grab a code sample. – Zev Eisenberg May 11 '14 at 13:42
  • @ZevEisenberg Yes, I know. I've looked into it and that idea is not bad but, like you said, it only provides *some* attributes. Things like `UltraLightItalic` and `ThinItalic` are not on the list (from what I can see, anyways). – Alex May 11 '14 at 13:45