Setting size to custom iOS font doesnt work

前端 未结 2 962

I am using some custom fonts in my iphone app. They are displayed correctly, but i cant change their size.

Here is how set this font for UILabel:

myL         


        
相关标签:
2条回答
  • You need to add your font in your Xcode, if you are adding manually.

    1. Add your font in your project files
    2. Go to your Project name-Info.plist file, right click and click Add Row.
    3. In your new row type Fonts provided by application. If you expand it you can add new items, in there add value to item 0 . The value should be your font file name. like below image

    enter image description here


    4. Double click on your font, it'll open in external editor, like following image

    enter image description here


    5.Give that name into your fontWithName: method. If you are setting value to your tableviewcell. the code will be
    cell.nameLbl.font = [UIFont fontWithName:@"Cabin" size:18.0];

    It works fine for me. I hope it helps :)

    0 讨论(0)
  • 2020-12-21 09:13

    Are you sure the font is loaded correctly?

    You can try:

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

    This will show you all the fonts that are loaded. Make sure the same name "Cabin-Regular" is showing up exactly the same. A lot of times the font itself isn't loaded and then the font-size won't be used at all.

    0 讨论(0)
提交回复
热议问题