Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 9 custom fonts not working

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?

like image 591
MobileMon Avatar asked Sep 19 '17 14:09

MobileMon


People also ask

How do I use custom fonts in Xcode?

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.

How do I use custom fonts in SwiftUI?

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.


1 Answers

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 :

  1. First select your font.ttf file inside bundle and on right side under File Inspector check mark the Target Membership option for your project.

  2. 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)

  3. 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 :)

like image 81
Prashant Gaikwad Avatar answered Oct 12 '22 01:10

Prashant Gaikwad