Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

-[NSString sizeWithFont:] returns different results in release and debug builds [duplicate]

I've used this code to resize a UILabel's frame height to fit dynamic text several times with success:

(...)
CGSize labelSize = [thelabel.text sizeWithFont:font constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];

All was well until I started to build my apps using the iOS5 SDK.

For armv6 devices (iPhone3G/-), when building for debug, the label size is okay, but when building for release, the height value retrieved is the same as the width. I am running both of these builds on an actual device.

example with following log line:

NSLog(@"labelSize: %f %f", labelSize.width, labelSize.height);

output: iphone3G - debug >

Thu Nov 3 18:22:50 unknown appname[1071] : labelSize: 115.000000 19.000000

iphone3G - release >

Thu Nov 3 18:22:50 unknown appname[1071] : labelSize: 115.000000 115.000000

Can anyone help or provide me with another solution to adjusting UILabel's height based on the text length?

I'm aware there are some similar questions about this method, but they do not address this particular issue.

like image 269
vfonseca Avatar asked Feb 03 '26 06:02

vfonseca


1 Answers

Had the same issue.

If you follow the link supplied by vfonseca, you arrive at: Is there a way to compile for ARM rather than Thumb in Xcode 4?

And the selected answer tells you how to add the correct compiler flags to prevent this. Alternatively upgrade to Xcode 4.3 which has fixed this bug.

like image 112
Paul de Lange Avatar answered Feb 04 '26 21:02

Paul de Lange