문제

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

도움이 되었습니까?

해결책 2

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top