vemoxy
vemoxy

Reputation: 1035

Custom fonts on iOS app - working in Simulator but not iPad

Encountering a weird problem here. I'm developing a game for my school project (non-commercial), and I'm using a custom font Black Chancery (free under GNU GPL). I followed the instructions from multiple sources, which includes:

I could get the font displayed in the Simulator, however when I load it into my iPad, the default system font is used. I'm pretty sure there isn't a problem with the font itself as it displays in the simulator, and I've used FontForge to open the font without any warnings (following from This Question).

Any help is greatly appreciated. Thanks! :)

Upvotes: 11

Views: 9562

Answers (8)

Js Lim
Js Lim

Reputation: 3695

I have the same issue on Xcode 6. My file name was My Font.ttf, it doesn't work. I manage to make it works when I rename it to My Font.TTF, just change the file extension to uppercase.

Upvotes: 0

Tintenklecks
Tintenklecks

Reputation: 507

You have to use the real font name in the [UIFont fontWithName:@"... method! Not the ttf filename!!!

This real name is mostly far away from the filename. Just open the rtf in the Mac font utility. In the header you see the font family!!! Only the family!!! if you now use

NSArray *fontNames = [UIFont fontNamesForFamilyName:@"MyFontNameFamily"];
NSLog(@"%@", fontNames);

in your code, you get the real real real name in the console ;-)

But in the plist entry you still need the (case sensitive) filename!!!

Upvotes: 0

vaughan
vaughan

Reputation: 7445

Also check that your fonts are not zero bytes. I had this same issue and it turned out that my font files had emptied themselves at some stage. Probably when rearranging them in XCode and AppCode.

Upvotes: 0

INSITE GURU
INSITE GURU

Reputation: 133

My answer is different from all the rest. I had a problem because the font was all one word and lowercase "compassnormal.ttf" and the name in the file was Compass. So, my code was:

[UIFont fontWithName:@"Compass" size:24]]

Bundle Resource said: compassnormal.ttf

~info.plist said: compassnormal.ttf

None of this worked until I changed the actual filename to match it's official name in fontbook.

  1. deleted all references from Bundle Resources and ~info.plist;
  2. added font with updated name to Bundle Resources;
  3. updated plist with new name;
  4. tested in simulator and on device, Voila!

Upvotes: 2

iphonic
iphonic

Reputation: 12719

I was having problem with font not recognizing, I fixed it by checking the correct name of the font by checking info of the font file by Get Info option. In my case the file name was written xyzfont.ttf but actually it was XyzFont.TTF in the info, i replaced and it worked.

Hope, it helps someone.

Another Way I have come across one more way of finding the correct name, is by installing the font in the FontBook..

Just open FontBook from Finder and select User now from File->Add Fonts select the font you want to add into your application, after little processing the FontBook will show the Font listed in with the Correct name, use the name in the FontBook ignoring the actual ttf file name you have imported or, added to plist.. It should work..

Upvotes: 11

SarpErdag
SarpErdag

Reputation: 781

I have also experienced a problem with fonts containing the dash (-) character. Remove that character from your font names and try with that.

So your font named Gotham-Black.ttf should be named GothamBlack.ttf

Upvotes: 0

kuruppsify
kuruppsify

Reputation: 53

I had the same problem which was resolved with a slight variation on iphonc's solution. The case sensitivity was directly related to the file extension. The problem was associated with my font file named: Choc.TTF

  1. I had to remove the reference to the file in xCode 4.1
  2. Rename the file to Choc.ttf (note lower case file extension)
  3. Add the reference back into xCode
  4. Perform a clean and re-build for the device

Conclusion (in my particular case):

Case sensitivity applies not JUST to the file name, but to the file extension as well (i.e. iOS device appears to tolerate only lower case).

Upvotes: 3

Anomie
Anomie

Reputation: 94794

I can only guess as you haven't posted the contents of your plist or a directory listing of the bundle, but many cases of "resource works on the simulator but not on the device" are caused by the fact that the OS X filesystem is normally configured to be case-insensitive while the filesystem on the device is case sensitive. For example, if your file is named "BlackChancery.TTF" and your plist refers to it as "BlackChancery.ttf", it will be found on the simulator but not on the device.

Upvotes: 39

Related Questions