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?

2
  • What happens when you try it? Is the label's adjustsFontSizeToWidth property set to YES? Is the label big enough to display its entire contents with that font at that size? Commented Dec 10, 2012 at 9:23
  • I updated question with more data. Commented Dec 10, 2012 at 10:09

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.