How to use a custom font on iOS

Sun, Jun 9

Next, add a property in the project plist named UIAppFonts, which is an array containing the names of each font you would like to make available in the application – if you are using the Property List Editor in Xcode, select Fonts provided by application from the dropdown list. Add an entry for each font:

The property list below is the text version of the plist file, here you can see the key UIAppFonts, the array and each of the two font entries:

To access the fonts within an application, call the method fontWithName in the UIFont class, include the font size as well:

UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 240, 40)];
[label1 setFont: [UIFont fontWithName: @"Grinched" size:24]];
[label1 setText:@"Grinched Font"];
[[self view] addSubview:label1];  
 
UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(10, 80, 240, 40)];
[label2 setFont: [UIFont fontWithName: @"Energon" size:18]];
[label2 setText:@"Energon Font"];
[[self view] addSubview:label2];

The output of the above looks as follows in the simulator:

To get a list of all the available font family names in your app, add this to your code:

NSLog(@"Available fonts: %@", [UIFont familyNames]);
-->

It’s surprisingly easy to add custom fonts to your iOS app. This tip will show you the steps, from updating the application plist to specifying the font name in your code…

Begin by adding the font(s) to your project, (drag/drag into the resources folder in the Project Window).


Next, add a property in the project plist named UIAppFonts, which is an array containing the names of each font you would like to make available in the application – if you are using the Property List Editor in Xcode, select Fonts provided by application from the dropdown list. Add an entry for each font:

The property list below is the text version of the plist file, here you can see the key UIAppFonts, the array and each of the two font entries:

To access the fonts within an application, call the method fontWithName in the UIFont class, include the font size as well:

UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 240, 40)];
[label1 setFont: [UIFont fontWithName: @"Grinched" size:24]];
[label1 setText:@"Grinched Font"];
[[self view] addSubview:label1];  
 
UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(10, 80, 240, 40)];
[label2 setFont: [UIFont fontWithName: @"Energon" size:18]];
[label2 setText:@"Energon Font"];
[[self view] addSubview:label2];

The output of the above looks as follows in the simulator:

To get a list of all the available font family names in your app, add this to your code:

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