4

I'm using this method to embed custom fonts in my iPhone app.

The embedding works: When I run the following code, the fonts are listed. (Currently, I'm embedding all family members of Myriad Pro in OTF format)

for( NSString *familyName in [UIFont familyNames] ){
    for( NSString *fntName in [UIFont fontNamesForFamilyName:familyName] ){
        NSLog(@"%@", fntName);
}}

When I try to set the font of a label to MyriadPro or MyriadPro-Bold, this works just as expected. However, when I set the font to MyriadPro-BoldCond, the label is still set in MyriadPro-Bold instead of the condensed version. (The font names are correct, I checked.) My Code:

[recommendationLabel setFont:[UIFont fontWithName:@"MyriadPro-BoldCond" size:140]];
recommendationLabel.adjustsFontSizeToFitWidth = YES;

What's the deal?

Edit: In addition to Ingve's solution below, I have found out that – at least for Myriad Pro – the correct font variant gets displayed as soon as I remove unused fonts from the plist. In this case I needed to remove MyriadPro-SemiBold. Mindboggling.

Community
  • 1
  • 1
winsmith
  • 20,791
  • 9
  • 39
  • 49

2 Answers2

5

UIFont is limited to two variations per font family. However, you can work around this by opening the additional n-2 fonts in an editor and changing the family name.

Answered my own question about this here: UIFont fontWithName: limited to loading 2 variations per family

Community
  • 1
  • 1
Ben Mosher
  • 13,251
  • 7
  • 69
  • 80
2

Maybe it is a limitation of UIFont? Have you tried using Core Text?

According to iOS Core Text Fonts, "Core Text doesn’t give you access to more fonts, but it provides support for a lot more font variations. To give an example: Helvetica Neue has 4 variations when you use UIFont whereas it has 11 variations when using Core Text."

Ingve
  • 1,086
  • 2
  • 20
  • 39
  • Seems interesting. I'll try and report back. – winsmith Jan 09 '11 at 12:09
  • 2
    And I'm back. Using Core Text does indeed work. However, it's a LOT of work compared to using NSLabel, especially if you've been using Interface Builder to layout your application as I have done. – winsmith Jan 10 '11 at 06:29