UILabel - set custom fonts

放肆的年华 提交于 2019-12-06 10:42:43

问题


I want to add GillSans-Bold font to a UILabel. I have set it in the xib file , and I'm also setting it up in my class as follows :

[label setFont:[UIFont fontWithName:@"GillSans-Bold" size:18]];

But , it doesn't seem to work for me. Any suggestions ?


回答1:


iPhone 4.3 doesn't have Gill Sans, but iPad has it since 3.2.1.

See this list comparing fonts for iPad 4.3 and iPhone 4.3. To be sure, this is how you get the list of fonts available on your device:

for (NSString *familyName in [UIFont familyNames]) {
    for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
        NSLog(@"%@", fontName);
    }
}

If it says

GillSans
GillSans-Bold
GillSans-BoldItalic
GillSans-Italic

then [UIFont fontWithName:@"GillSans-Bold" size:18] should return a valid font.




回答2:


For this to be working I had to add this font in my project directory , and added this font in the Info.Plist file




回答3:


Does the font GillSans-Bold exist? Check if [UIFont fontWithName:@"GillSans-Bold" size:18] returns an UIFont, not null.



来源:https://stackoverflow.com/questions/8151262/uilabel-set-custom-fonts

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