简体   繁体   中英

UIScrollView dynamically resize UILabel

i have got a UILabel which is not static.

I want to resize my scroll view so that it fits the label.

Here is my idea now:

self.scrollView.contentSize = CGSizeMake(320.0, 92+self.contentLabel.frame.size.height);

92 stands for pixels from where my label start. (there is a heading too)

But it doesn't work, it seems to be connected with Interface Builder also.

Thanks guys.

You need to set the frame as well. The contentSize of the scrollview is just what is within, not the frame of the view itself. If the contentSize is greater than the frame it will result in scrolling.

CGSize buttonSize =  CGSizeMake(320.0, 92+self.contentLabel.frame.size.height);
self.scrollView.contentSize = buttonSize;
self.scrollView.frame = CGSizeMake(0, 0, 320.0, buttonSize.width, buttonSize.height);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM