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...

fibnochi
  • 1,113
  • 1
  • 9
  • 26

1 Answers1

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.

omz
  • 53,243
  • 5
  • 129
  • 141
  • I have removed the extension but still size is (0,0) – fibnochi May 10 '12 at 07:12
  • 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... – omz May 10 '12 at 07:25
  • ...and make sure that you've included the font in your Info.plist. – omz May 10 '12 at 07:25
  • 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. – fibnochi May 10 '12 at 07:51
  • I know I can make text bold by adding -Bold after font name – fibnochi May 10 '12 at 08:01
  • Have you also included the bold font file and added it to your Info.plist? The bold font is in a different file than the normal font... – omz May 10 '12 at 08:05
  • Thanks omz. I will buy bold fonts too – fibnochi May 10 '12 at 08:46