12

I've been playing around with custom fonts in iOS and have got most of it figured out apart from the custom font won't show on any of my devices.

  1. I have added the font to the root of the project file.
  2. Added it to the info.plist file under the array or "Fonts provided by application"
  3. Checked that the case sensitivity of both the original file and what I added to the info.plist file are the same.
  4. Used [playMenuBtn.titleLabel setFont:[UIFont fontWithName:@"fontname" size:40]]; to make the font work.

When I run my app in the Simulator it all appears fine and works. However as soon as I run it on a physical device, it displays the default font with the default size.

If I use:
UIFont *font = [UIFont fontWithName:@"VINCASTENCIL" size:20]; NSLog(@"Font:%@", font);

Then the simulator returns: 2012-04-07 01:10:41.544 AppName[47412:f803] Font:<UICFFont: 0x683e040> font-family: "VINCA STENCIL"; font-weight: normal; font-style: normal; font-size: 20px

Where as the device returns: 2012-04-07 00:42:56.358 AppName[5079:707] Font:(null)

I have tried everything, including trying all the names that FontBook tells me the font could be named. I know it's free and there isn't a licence on it.

Any help would be greatly appreciated as it's driving me nuts and I really don't want to use images for al of these as localisation would then be a pain!

Arun_
  • 1,806
  • 2
  • 20
  • 40
Baza207
  • 2,123
  • 1
  • 22
  • 40

2 Answers2

29

Right, I've just managed to get this working. Everything I was doing was correct but for some reason it wasn't adding my font file to 'Targets' -> 'Build Phases' -> 'Copy Bundle Resources'. By manually adding it to this list, the font then shows on the device.

This is the second time this project has not added a file here automatically (it's done it previously with a class I added, and it didn't) so I think it's something wrong with my project, or a bug in Xcode.

Thanks to everyone for your suggestions and help. :-D

Baza207
  • 2,123
  • 1
  • 22
  • 40
  • This is sort of what I sad D: – Allison Apr 07 '12 at 14:52
  • @TheDeveloper yeah was the reason I checked it in the end. Thanks! :-) – Baza207 Apr 07 '12 at 16:24
  • Seems like xcode doesn't add TTF files to the bundle resources by default, unlike eg png's. Same problem here, – Chris Jul 11 '12 at 09:12
  • I'm also facing same problem but fonts are showing in Copy Bundle Resources.i Added two custom fonts. One font is working but the second one is not working ... i dunno why – Omer Obaid Jan 22 '14 at 06:52
  • @OMerObaid I found double checking the name it's called useful as well. Best way to see if your device knows a font is there is looping through `[UIFont familyNames]` and `[UIFont fontNamesForFamilyName:]` and log out the font names. FontBook is also really great for seeing what a font should be named. – Baza207 Feb 02 '14 at 12:10
0

Yes, follow all the directions mentioned above and you should be fine. Something else to look out for: case sensitivity. In your *.plist file and Fonts provided by application. The simulator might ignore capitalization, but the device will not. For example, 'Facebook' is not the same as 'FaceBook'. (This led to the font working in the simulator, but not the device!)

Jeremy C.
  • 640
  • 6
  • 8