12

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?

MobileMon
  • 8,341
  • 5
  • 56
  • 75
  • You don't mention the results of the code you posted. And define "not working". Never use those words without a complete description of exactly how it's not working. – rmaddy Sep 19 '17 at 15:00
  • Have you tried [this](https://stackoverflow.com/a/34157634/6233138)? – Jeremy Sep 19 '17 at 15:01
  • By "not working" I mean: when I programmatically set the font of a UILabel, the font is not rendered. Instead I believe its showing the default system font – MobileMon Sep 19 '17 at 15:05
  • I can assure you that custom fonts are working on Xcode 9. Can you show us more of how you're setting them on your labels? – picciano Sep 19 '17 at 15:51
  • I just use the standard way: myLabel.font = [UIFont fontWithName:@"HelveticaLTStd-BoldCond", size:17] – MobileMon Sep 19 '17 at 15:57
  • And is that exact font name shown in the code you posted? – rmaddy Sep 19 '17 at 16:04
  • 1
    Yes, and that exact font name works in Xcode 8 – MobileMon Sep 19 '17 at 16:05
  • 1
    I tried deleting the fonts and re adding them, and also restarting Xcode – MobileMon Sep 19 '17 at 16:06
  • What's even more strange is I use another font "FontAwesome" and that one does work. So something is going on with HelveticaLTStd-BoldCond. There is actually a few other Helvetica custom fonts I bring in that no longer work either – MobileMon Sep 19 '17 at 18:01
  • My apologies the name is Helvetica-Condensed-Bold – MobileMon Sep 19 '17 at 18:13
  • You should delete the question since you found your mistake. – rmaddy Sep 19 '17 at 19:37
  • 1
    The problem still exists, I listed the wrong font name in the comments here. Still, Helvetica-Condensed-Bold will not work in Xcode 9 but does in Xcode 8 – MobileMon Sep 20 '17 at 11:20
  • I solved custom font issue in my xcode 9 .Here are the following steps- 1- Add to the font in bundle, 2- add in plist file font name under Fonts provided by application 3- Go to Target->build phase and add your font files. Now u can build your project. It will show to the custom font in your application. – Pravesh Uniyal Oct 11 '17 at 06:17
  • @MobileMon Were u able to solve it? I am receiving the same problem. I am not able to add new font in XCode 9. – Bharath Reddy Apr 23 '18 at 08:07
  • No, I haven't resolved this issue yet – MobileMon Apr 23 '18 at 14:12

5 Answers5

5

I have this issue ,,

make sure that you Click on your font folder to make sure they are included in your “Target Membership.”

enter image description here

Ahmed Safadi
  • 4,402
  • 37
  • 33
3

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

Prashant Gaikwad
  • 3,493
  • 1
  • 24
  • 26
1

Had the same problem after opening project in Xcode 9, solved it by reincluding the fonts. (deleted them, cleaned project, included them, built project).

Altough you got them checked in the target, but not visible to chose as custom font, you can try to specify the localization (above target check) to 'base' or some, it made them visible in Storyboards after that, but unable to load in code (at least in my case). However, reincluding is imo better way to go, it made everything OK.

Tomáš John
  • 314
  • 4
  • 14
1

I solved custom font issue in my projects using Xcode 9. Here are the following steps-

1- Add to the font in the bundle. 2- add in plist file font name under Fonts provided by application 3- Go to Target->build phase and add your font files.

Now you can run your project.It will show to the custom font in your application.

1

It presents a problem for the compiler if it is located inside a blue directory folder (apparently) I moved my font file outside the folder, build and problem solved (GRR!)

Bil Kimes
  • 11
  • 1