0

I have a Label that displays some text like "I am good". How can I calculate the size of text in Label that has custom font. I am calculating size like

CGSize s = [mSubLabel.text sizeWithFont:[UIFont fontWithName:@"ArnhemPro-Blond.otf" size:10.0] constrainedToSize:Max_Size lineBreakMode:UILineBreakModeTailTruncation];

NSLog(@"expected size %@",NSStringFromCGSize(s));

But the size is (0,0)

How can i calculate the size? using GSize subLabelSize=[mSubLabel.text sizeWithFont:[UIFont systemFontOfSize:1] constrainedToSize:Max_Size lineBreakMode:UILineBreakModeTailTruncation];

gives me size but that is not correct.help please...

2
  • 1
    The link has your answer. [1]: stackoverflow.com/questions/3527494/… Commented May 10, 2012 at 6:22
  • @mihirios: I am using custom fonts not the font of Label. Commented May 10, 2012 at 7:11

1 Answer 1

1

Your font is most likely nil, the name parameter for fontNamed: should be the name of the font which is usually different from its filename (and has no extension). You can use the Font Book app to find out the actual name of a font.

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

7 Comments

I have removed the extension but still size is (0,0)
Btw, make sure you have a proper license for the font. The usual licenses that you can buy online normally don't allow to embed them in apps, you'd need to have a special license for that and those tend to be expensive...
...and make sure that you've included the font in your Info.plist.
I have purchased fonts and also I have added them info.plist. Now I am able to get size but when I try to get size for bold text it shows (0,0). Any how I will your answer is correct if I am to get size for bold text too.
I know I can make text bold by adding -Bold after font name
|

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.