9

i have added a custom font - one which i have downloaded from from the net. it is in TTF format and can be used on other programs on my mac. (Successfully added it to font book and used in fireworks).

I have added the key to the info .plist but the font doesn't seem to work.

When i NSLog the font it is null so i am assuming it isn't finding it.

The TTF is called LONDON__.TTF but has a name as London font.

What should i use as the font and add to the info.plist for this to work?

Thanks

Dan

Application fonts resource path = LONDON__.TTF

NSLog(@"%@",[UIFont fontWithName:@"London font" size:22]);

and

NSLog(@"%@",[UIFont fontWithName:@"LONDON__.TTF" size:22]);

Both of them return Null.

Although the file is named LONDON__.TTF the font appear as everyone in Font Book. is this the issue?

1
  • What did you put in your Info.plist?
    – rob mayoff
    Jan 22, 2012 at 18:44

3 Answers 3

38

Look at all the available fonts

Objective-C:

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

Swift:

for family: String in UIFont.familyNames() {
    print("%@", family)
    for name: String in UIFont.fontNamesForFamilyName(family) {
        print("  %@", name)
    }
}

..if it's not there, install again

  1. Copy the .ttf file into your project (i.e. drag it to the resource folder in the Project navigator).

  2. In your Info.plist add an entry with the key Fonts provided by application with an Array type. As Item 0, add a String value corresponding to the font file name (e.g. OpenSans-ExtraBoldItalic.ttf).

  3. Make sure the font file is included in the copy bundle resources list under the project settings.

7
  • thanks it doesn't appear so i assume its not added correctly. any ideas?
    – Dan
    Jan 22, 2012 at 18:43
  • As Rob Mayoff asked, edit your question to include the .plist entry.
    – user371320
    Jan 22, 2012 at 18:49
  • Did you add the font file to your project?
    – user371320
    Jan 22, 2012 at 19:01
  • I've updated my answer with the .plist key you should be using.
    – user371320
    Jan 22, 2012 at 19:13
  • Why can't you see it? "Fonts provided by application"
    – user371320
    Jan 22, 2012 at 20:12
6

You need to make sure the font file is included in the copy bundle resources list under the project settings. My font wouldn't show up in [UIFont familyNames] till I added it here as it was not automatically included when added to the project.

1

Both of those names sound wrong. Assuming you've correctly added it to your plist, use something like

NSLog(@"Fonts: %@", [UIFont familyNames]);

to see what its internal name is.

BTW, be sure that the licensing of the font allows embedding. Many commercial fonts do not.

2
  • thanks it doesn't appear so i assume its not added correctly. any ideas?
    – Dan
    Jan 22, 2012 at 18:47
  • So it's in your plist like <key>UIAppFonts</key> <array> <string>Dutch Mediaeval.ttf</string> </array> and part of the project? Jan 23, 2012 at 0:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.