简体   繁体   中英

Setting size to custom iOS font doesnt work

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:

myLabel.font=[UIFont fontWithName:@"Cabin-Regular" size:18];

This label is part of uitableview cell, if that could play any role.

Label settings in IB:

在此输入图像描述

I change only color, text and font in code for this label.

What could be wrong?

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.

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

在此输入图像描述


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

在此输入图像描述


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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM