views:

16

answers:

1

I have a few UILabels in my view with their height set using sizeWithFont:.

I set the autoreszingMask to flexible width and height, however on rotate the width changes (am assuming because self.view's width changes and its set with a width relative to self.view) but the height of it doesn't change to fit the content again. This results in a large white space at the top and bottom.

Just wondering how I would go about re-sizing the UILabel on rotation? Is there any automatic way of doing this, or is there a way of getting all UILabels and re-doing sizeWithFont when the device is rotated?

The UILabels are subviews of UIView heirarchies used as headers for sections in my UITableView.

Thanks Tom

A: 

You should really send sizeToFit to any UIView, especially UILabel, instead of forcing some arbitrary size on them.

The best approach is usually to first set the maximum width and current height, then send sizeToFit, then adjust the width again if necessary. In case of multiline labels it looks like the most foolproof way to avoid layout bugs.

Costique
sizeToFit results in really irrational behavior... how are you meant to use it? Thanks
Thomas Clayson
What is the problem you see?
Costique
well... I don't really know. It seems to just choose a random width and height, sometimes cutting off text, and sometimes just being strangely high. Rotating the device only changes the width.
Thomas Clayson