UILabel - set custom fonts

2020-07-26 11: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.



标签: ios uilabel