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

前端 未结 8 1203
故里飘歌
故里飘歌 2021-02-08 07:11

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 th

相关标签:
8条回答
  • 2021-02-08 08:00

    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!!!

    0 讨论(0)
  • 2021-02-08 08:02

    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

    0 讨论(0)
  • 2021-02-08 08:07

    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.

    0 讨论(0)
  • 2021-02-08 08:08

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

    0 讨论(0)
  • 2021-02-08 08:10

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

    0 讨论(0)
  • 2021-02-08 08:11

    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!
    0 讨论(0)
提交回复
热议问题