UILabel - set custom fonts
Asked Answered
C

4

2

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 ?

Countercheck answered 16/11, 2011 at 11:56 Comment(1)
This is helpful: iosfonts.com - shows what iOS version has which stock fonts.Disbud
C
3

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

Countercheck answered 25/11, 2011 at 9:17 Comment(0)
D
12

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.

Decorous answered 16/11, 2011 at 12:22 Comment(0)
C
3

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

Countercheck answered 25/11, 2011 at 9:17 Comment(0)
P
2

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

Plugugly answered 16/11, 2011 at 12:10 Comment(1)
I tried this, and it's returning 'null' . The only font available in Gill Sans family is GillSans. Thanks. But is there any way I can render the UILabel text in GillSans-Bold font ?Countercheck
P
1

Swift

let label = UILabel()
    label.font = UIFont(name: "Roboto-Regular", size: 16)
    label.text = "Your text here"

P.S. Before that you must:

  1. Add custom font in project

enter image description here

  1. Add font names in Info.plist file

enter image description here

  1. Add font files in Copy Bundle Resources

enter image description here

After that you can also use this fonts in storyboards

enter image description here

Primus answered 8/1, 2021 at 9:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.