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 automat开发者_如何转开发ic 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
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.
The problem was having a flexible left and right margin on a slightly offset uilabel.
If the label isn't centered then you need to choose left or right and set the flexible margin for one of those.
精彩评论