UIFont custom font not displaying on device

不打扰是莪最后的温柔 提交于 2019-12-07 14:01:31

问题


I have a problem with custom font. Namely it's Tw Cen MT.ttf

It's the same problem as in here: Custom font not showing on device, but does on simulator

Except the given solution doesn't work for me.

I have done exactly what you should do:

  1. Added Font to Info.plist
  2. Added Font to Copy Bundle Resources section in Build Phases.
  3. Used font programmatically by name not filename.

It still doesn't work. What's more interesting - when I list available fonts:

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

It shows me my font on simulator but does not show it on the device. I tested it both on the new iPad and iPhone 4 with iOS 6.

Any advice?


回答1:


Be sure not to confuse the family name with the font name. This is the code I use to check the real name of my fonts.-

NSArray *familyNames = [UIFont familyNames];
for (NSString *aFamilyName in familyNames) {
     NSArray *fontNames = [UIFont fontNamesForFamilyName:aFamilyName];
     for (NSString *aFontName in fontNames) {
        NSLog(@"%@", aFontName);
     }
}



回答2:


Make sure you got the name of the font right. The simulator is not case sensitive whereas the phone is.



来源:https://stackoverflow.com/questions/15889942/uifont-custom-font-not-displaying-on-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!