UIScrollView dynamically resize UILabel

随声附和 提交于 2019-12-25 08:56:10

问题


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.


回答1:


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);


来源:https://stackoverflow.com/questions/11902223/uiscrollview-dynamically-resize-uilabel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!