UIScrollView动态调整UILabel的大小 [英] UIScrollView dynamically resize UILabel

查看:145
本文介绍了UIScrollView动态调整UILabel的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不是静态的UILabel。

i have got a UILabel which is not static.

我想调整滚动视图的大小以适合标签。

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

这是我的主意:

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

92代表标签开始的像素。 (也有标题)

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

但是它不起作用,似乎也与Interface Builder相连。

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

谢谢。

推荐答案

您还需要设置框架。滚动视图的 contentSize 只是其中的内容,而不是视图本身的框架。如果 contentSize 大于框架,则会导致滚动。

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

这篇关于UIScrollView动态调整UILabel的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆