Issues with custom font in iOS

烈酒焚心 提交于 2020-01-21 06:04:30

问题


I followed the steps outlined in various locations using the UIAppFonts property list key. I'm using the Aller Light font. I've added it as a resource, added the font name correctly in the info property list, and am now attempting to use it, however every attempt to do so results in the default font being displayed. So far I've tried:

[leader setFont:[UIFont fontWithName:@"Aller Light" size:20.0]];
[leader setFont:[UIFont fontWithName:@"AllerLight" size:20.0]];
[leader setFont:[UIFont fontWithName:@"Aller-Light" size:20.0]];
[leader setFont:[UIFont fontWithName:@"Aller-Lt.ttf" size:20.0]];

leader.font = [UIFont fontWithName:@"Aller Light" size:20.0];
... with all the variants listed above

None of them work. Running NSLog(@"Available fonts: %@", [UIFont familyNames]); returns:

Available fonts: (
    ...
    "Aller Light",
    ...
)

Thoughts or solutions? Installing the font on my mac and looking in Font Book, the name of the font is Aller Light. Verifying the font in Font Book indicates that the font name is in fact simply Aller Light.


回答1:


List all fonts

for (NSString *name in [UIFont familyNames]) {
    NSLog(@"Family name : %@", name);
    for (NSString *font in [UIFont fontNamesForFamilyName:name]) {
        NSLog(@"Font name : %@", font);             
    }
}


来源:https://stackoverflow.com/questions/9750222/issues-with-custom-font-in-ios

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