View Full Version : sizeToFit behavior changed for iOS 6.0?

Sep 20, 2012, 12:16 AM
I just downloaded XCode 4.5 and iOS 6.0, and compiled it for my app, and noticed when running iOS 6.0
on the simulator, the behavior of "sizeToFit" has changed.

I'm using a UILabel with text that changes in size over time (a scoreboard), e.g:

[self.myLabel setText:myString];
[self.myLabel sizeToFit];

And my score no longer fits. I can't even see it.

Before, the label would "expand" to fit the text, but now, the label only "contracts" to fit.
It does not expand anymore.

What's up with this change? :confused:
How do you fit a UILabel with text that can grow or contract?

Nov 14, 2012, 10:45 AM
has anyone found a fix for this yet? I am running into issues. I want to know if its io6 related or me related

Nov 14, 2012, 12:00 PM
Why wouldn't you just make the UILabel as large as possible? sizeToFit will shrink it if the label is larger than necessary, and in the event that its too large, well, tough luck, because the screen size is only so big?

(I've never used sizeToFit, so my understanding of it might be... Wrong.)

Nov 14, 2012, 12:31 PM
What ArtOfWarfare said. Just size your UILabels with the maximum amount of space you have available for the label, and call sizeToFit if you want to shrink it.

If you need to calculate the size of a UILabel for a given string, try sizeThatFits: