Using a custom font in iOS requires a few steps:
- Have access to the TTF or OTF file for the desired font.
- Drag the TTF or OTF font file into your Xcode project.
- Located the application's Plist file and add a new row with the key "Fonts provided by the application.
- Make sure that the associated value in the Plist perfectly matches the naming of the dragged in font file.
In your code, you can now assign the custom font to be used with your label, textfield or any other control that has the font
property.
[myLabel setFont:[UIFont fontWithName:@"Benguiat Gothic" size:12.0f]]
;
Or, if you prefer dot notation syntax
myLabel.font = [UIFont fontWithName:@"Benguiat Gothic" size: 12.0f];
There's a few things to take into consideration. The actual naming of the Font File may not always be what you have to pass in as a string literal. Some custom fonts may have different weights associated with it (Light, Regular, Medium, Bold, Italic Bold etc). If the font isn't displaying as you would expect and all steps above have been explicitly followed then it could be down to the string you're using in your code.
You can get the list of font family names in debug by logging out as so:
NSLog (@"Font families: %@", [UIFont familyNames]);
That should give you a decent indication of what to actually use in your code when defining the custom font for use with the label.