Embedding custom fonts
suggest changeCustom font support: applications that want to use custom fonts can include those fonts in their application bundle and register them with the system by including the
UIAppFontskey in their Info.plist file. The value of this key is an array of strings identifying the font files in the application’s bundle. When the system sees the key, it loads the specified fonts and makes them available to the application.
Once the fonts are listed in Info.plist, you can use them like any other font in Interface Builder or in code.
- Drag the font file into the Xcode project. Select the app target under Add to targets. The file name in the plist is not enough by itself. The font also has to be in the app target.
-
To make the font available on the device, open
Info.plistand add Fonts provided by application (UIAppFonts). Item 0 is the font file name, including its extension, such asCustomFont.ttf. The name you pass toUIFont(name:)is the PostScript name printed by the snippet below. That name can differ from the file name. -
Print the installed family and PostScript names:
Swift 3
for family in UIFont.familyNames {
print("\(family)")
for name in UIFont.fontNames(forFamilyName: family) {
print(" \(name)")
}
}
Objective-C
for (NSString *familyName in [UIFont familyNames]){
NSLog(@"Family name: %@", familyName);
for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
NSLog(@"--Font name: %@", fontName);
}
}