Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

samdev

macrumors regular
Original poster
Sep 16, 2011
126
0
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:

Code:
[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?
 

12991

macrumors member
Feb 3, 2007
71
0
has anyone found a fix for this yet? I am running into issues. I want to know if its io6 related or me related
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,560
6,059
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.)
 

Reason077

macrumors 68040
Aug 14, 2007
3,606
3,644
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:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.