Custom fonts not working in Xcode 9. However if I open the same project in Xcode 8, the custom fonts work as expected
I've ran this piece of code to ensure the fonts show up:
NSArray *fontFamilies = [UIFont familyNames];
for (int i = 0; i < [fontFamilies count]; i++)
{
NSString *fontFamily = [fontFamilies objectAtIndex:i];
NSArray *fontNames = [UIFont fontNamesForFamilyName:[fontFamilies objectAtIndex:i]];
NSLog (@"%@: %@", fontFamily, fontNames);
}
I've ensured the fonts are in the plist, checked target membership, and in the copy bundle resource section.
Is this an Xcode bug?
To add a font file to your Xcode project, select File > Add Files to “Your Project Name” from the menu bar, or drag the file from Finder and drop it into your Xcode project. You can add True Type Font (. ttf) and Open Type Font (. otf) files.
To use a custom font, add the font file that contains your licensed font to your app, and then apply the font to a text view or set it as a default font within a container view. SwiftUI's adaptive text display scales the font automtically using Dynamic Type.
I am also using Xcode 9.2 and even I also faced same issues.
What I did is I directly added the custom font folders inside my app. If you directly add fonts folder then you may face such issues.It will not reflect your font files under Copy Bundle Resources inside Build Phases tab. To solve this problem I used following steps :
First select your font.ttf file inside bundle and on right side under File Inspector check mark the Target Membership option for your project.
Goto project target and under Build Phases goto Copy Bundle Resources and add all your fonts by clicking on + button.(make sure you adding your font.ttf files only not the folder containing that font.ttf file)
Also make sure your file are properly added while dragging them inside your project.Don't forget to check Copy items if needed option. Most important do add the key Fonts provided by application in your info.plist file followed by all the custom fonts you used in your project.
Hope this helps. Happy coding :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With