UILabel - set custom fonts

2020-07-26 11:30发布

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 ?

标签: ios uilabel
3条回答
Root(大扎)
2楼-- · 2020-07-26 11:48

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

查看更多
We Are One
3楼-- · 2020-07-26 11:57

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.

查看更多
来,给爷笑一个
4楼-- · 2020-07-26 12:07

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

查看更多
登录 后发表回答