Add a font to your project

Instead of the plain vanilla systemFontOfSize: in the Hello project, you can install a font from the web.

  1. Download a font. I used http://www.dafont.com/ to choose a font. For my example I chose to download: http://www.dafont.com/aez-wedding-dings.font. The file you want looks something like AEZweddingdings.ttf. This is a true type font (ttf). I suspect you can also do for an open type font (otf).

  2. Drag the font (the .ttf file) into the Supporting Files folder of the project.

  3. There are 2 places to make sure that the fonts are available to the app for normal use.
    1. XCode should automatically have placed the AEZweddingdings.ttf in the 'Copy Bundle Resources' listed under 'Build Phases' under your target. To confirm this, select the project in the Xcode Project Navigator, select the TARGET in the left pane of the Xcode central panel, and scroll down to Copy Bundle Resources.
    2. Here is the tricky step. In the Projectname-Info.plist file in the Supporting Files folder, you must add a row for 'Fonts provided by application'. The value needs to be the name of the .ttf file referenced above; in our case, AEZweddingdings.ttf.

  4. In the step following this one we will use the fontWithName:size: method of class UIFont to utilize the font in our app, however, discovery of the name is tricky for this method of import. I utilize the following to print out the fonts available to make sure the new font is there:
    	NSLog(@"%@", [UIFont familyNames]);
    
    There probably is a better way to figure out the name in a font tool or within Xcode, but this works.

  5. Finally, with the name in hand, you can import and use the font normally
    	UIFont *importedFont = [UIFont fontWithName: @"AEZ wedding dings" size: 28.0];
    	[@"abcdefg" drawAtPoint: CGPointMake(0, 0) withFont: importedFont];
    
    The string concatenation is pretty self-explanatory. The only odd step was when creating the new file, you select category.