How to add a true type font to an iOS project

Drop the .ttf file into your project. Then go into the main plist (usually named the project name.plist). Then go to the bottom most row and Add in ‘Fonts Provided by Application’. It will pop up with a lot of different configuration options.

plist adding font

The element is an Array and we’ll add the exact name of the font as a String inside that array.

 

You can verify that it is being included in your app by selecting the target, then the ‘Build Phases’ tab and it will be in ‘Copy Bundle Resources’.

Penultimately you need to know the exact name to call this font. It likely is not what the filename is. To fetch that use this code:

NSArray *availableFonts = [UIFont familyNames];
for (int i = 0; i < [availableFonts count]; i++)
{
    NSString *fontFamily = [availableFonts objectAtIndex:i];
    NSArray *fontNames = [UIFont fontNamesForFamilyName:[availableFonts objectAtIndex:i]];
    NSLog (@"%@: %@", fontFamily, fontNames);
}

I just tossed this into:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

Once I run the program it will immediately print all the font information in the output. It prints all available fonts not just the ones you added.

2014-05-04 09:20:05.771 Odell Lake[1639:60b] Times New Roman: (
    "TimesNewRomanPS-BoldItalicMT",
    TimesNewRomanPSMT,
    "TimesNewRomanPS-BoldMT",
    "TimesNewRomanPS-ItalicMT"
)
2014-05-04 09:20:05.771 Odell Lake[1639:60b] Telugu Sangam MN: (
    TeluguSangamMN,
    "TeluguSangamMN-Bold"
)
2014-05-04 09:20:05.771 Odell Lake[1639:60b] Print Char 21: (
    PrintChar21
)

Now that I know the name of my included font. I can use it thusly:

UIFont *customFont = [UIFont fontWithName:@"PrintChar21" size:20];

Bonus: Here’s the code to put your custom font onto a SpriteKit label.

        SKLabelNode *myLabel = [SKLabelNode labelNodeWithFontNamed:@"PrintChar21"];
        myLabel.text = @"Custom Font!";
        myLabel.fontSize = 30;
        myLabel.position = CGPointMake(CGRectGetMidX(self.frame),
                                       CGRectGetMidY(self.frame));
 
        [self addChild:myLabel];

Custom Font in Emulator