0

I'm trying to install a custom font (Open Sans from Google Fonts) and I did everything as some tutorials say and no success. I followed these steps and I can't use the custom font: http://www.practicalentrepreneur.com/how-to-use-a-custom-font-in-xcode-4-5-ios-6-0/

  1. I imported the .tff file to my project
  2. Associated the file with my target
  3. Added the reference in the plist file
  4. Also added the font in the Font Book app
  5. Clean, build and run

When I try to list the available fonts with this command:

NSLog(@"fontFamilies: %@", [UIFont familyNames]);

I don't get my imported font family printed.

I already tried some tips from these questions but nothing works:

  1. xcode custom ttf font not working
  2. Added custom font not working in Xcode
  3. OpenSans font not working in iOS simulator
  4. Custom font in a storyboard?

Thanks!

Community
  • 1
  • 1
Fabio
  • 1,757
  • 19
  • 33
  • What did you type into the plist file? The exact filename of the font file *with* the extension? Is it inside any folder references when you added it to your target? – borrrden Jul 24 '13 at 10:09
  • @borrrden I typed "OpenSans-Bold.tff", for example. This exactly the name of the font file that I imported. "Is it inside any folder references when you added it to your target?" - what do you mean? – Fabio Jul 24 '13 at 10:12
  • I mean in your file list is it inside a blue folder or a yellow folder... – borrrden Jul 24 '13 at 10:13
  • Hey, that's **ttf** not **tff** by the way. That could be your problem... – borrrden Jul 24 '13 at 10:16
  • @borrrden they're (it's 3 files) in a group folder (but not only referenced, I added copying the files to the project). – Fabio Jul 24 '13 at 10:17
  • @borrrden yeah, I know... I wrote here wrong, not there :) I will try to reimport everything again from the beginning and even restart the xcode. – Fabio Jul 24 '13 at 10:19
  • I added the fonts myself, and it shows up just fine. One more thing, make sure that you are actually copying them to the bundle (i.e. look at their properties and make sure the target is checked under **Target Membership**) – borrrden Jul 24 '13 at 10:22
  • @borrrden it was one of the first things that I checked. They're linked. As I told you, I will restart everything again. I let you know. Thanks btw! – Fabio Jul 24 '13 at 10:27
  • @borrrden I restarted my mac and xcode, cleaned, builded, ran and voooila: it's working! ¬¬ I hate xcode so much! Sorry about that, next time I will restarted everything again before ask to the community. Thanks a million! – Fabio Jul 24 '13 at 10:33

1 Answers1

1

In the plist file you should insert the font with the name provided in the Font Book app. In my case, the name of the font in the app is Chalet Comprime Cologne Sixty, but when i call it in code i have to call it like this

label.font = [UIFont fontWithName:@"ChaletComprime-CologneSixty" size:24.0];

So...try looking at the name of your font in the Font Book app.

Alexandre Lins
  • 306
  • 1
  • 2
  • 10