3

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:

enter image description here

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

What could be wrong?

DixieFlatline
  • 7,895
  • 24
  • 95
  • 147

2 Answers2

4

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.

app_
  • 697
  • 5
  • 12
  • I tried your code and my Cabin font is not printed. But i have it in plist correctly spelled (the same as ttf filename). – DixieFlatline Dec 10 '12 at 16:05
  • 2
    To add add a font to you project see the answer of arthan.v or try this http://refactr.com/blog/2012/09/ios-tips-custom-fonts/ (the same but with nice screenshots) – app_ Dec 10 '12 at 16:11
  • 1
    Your link in comments solved the problem. I had to click on my font in Xcode and check "Target membership". – DixieFlatline Dec 10 '12 at 20:55
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 :)

arthankamal
  • 6,341
  • 4
  • 36
  • 51