views:

13

answers:

1

Hello,

I'm using sizeWithFont:constrainedToSize:lineBreakMode: to calculate the actual height of a UILabel. However, the height I get is always based on the complete NSString (before it gets truncated).

In fact, both sizeWithFont:constrainedToSize:lineBreakMode: and sizeWithFont:constrainedToSize: produce identical results as if the UILineBreakModeTailTruncation gets ignored!

This code produces 60.000000 no matter what I try, but the first result should be less than 60. Any idea why?

CGSize aSize;

aSize=[@"One two three four five six seven eight nine ten" sizeWithFont:[UIFont boldSystemFontOfSize:12] constrainedToSize:CGSizeMake(100, 100)];

NSLog(@"aSize.height: %f",aSize.height); //returns 60.000000

aSize=[@"One two three four five six seven eight nine ten" sizeWithFont:[UIFont boldSystemFontOfSize:12] constrainedToSize:CGSizeMake(100, 100) lineBreakMode:UILineBreakModeTailTruncation];

NSLog(@"aSize.height: %f",aSize.height); //returns 60.000000

Thank you.

A: 

Sorry, I found out that the string did not get truncated because the frame can contain the entire string.

Jim
You should tag your own answer as the accepted answer, so that the question comes up as answered in the database.
August Lilleaas