【发布时间】:2014-07-08 11:42:28
【问题描述】:
我想要做的是,添加UIScrollView 和内部滚动UIView 和内部UIView 2 动态高度标签。现在我想将 UIScrollView 的高度设置为在页面底部滚动。
但是现在我正在无限滚动。谁能帮我处理这段代码?
UIScrollView *scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 155.0, 320, 513)];
UIView *myview = [[UIView alloc] initWithFrame:CGRectMake(0.0, 155.0, 320.0, FLT_MAX)];
UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 155.0, 320.0, FLT_MAX)];
lable.numberOfLines = 0;
lable.text = @"It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).";
[lable sizeToFit];
UILabel *slabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 480.0, 320.0, FLT_MAX)];
slabel.numberOfLines = 0;
slabel.text = @” It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).”;
[slabel sizeToFit];
scrollview.contentSize = CGSizeMake(scrollview.contentSize.width, myview.frame.size.height);
[myview addSubview:lable];
[myview addSubview:slabel];
[scrollview addSubview:myview];
[self.view addSubview:scrollview];
【问题讨论】:
-
FLT_MAX...?你究竟希望从3.40282347E+38F的小值中得到什么? -
放置这样一段代码的正确位置是
viewDidLoad或viewWillAppear。你到底把这段代码放在哪里了?最后,您在scrollView上设置contentOffset的位置在哪里? -
holex ...我是iOS的初学者,我正在努力完成这项工作。我在数据库中有 4 列想要在 UIScrollView 中的 UILable 中显示。所以我想做的是.. 做一个 for 循环并在 UILable 中为所有 4 列写入数据,但问题是我不知道所有 4 列将包含多少行代码。
-
Panayot Panayotov 我已将此代码放在 viewDidLoad 中。
标签: ios iphone uiview uiscrollview