也许我不明白你想要实现什么,但我认为问题是对UITextView
课程的滥用。正如UITextView
文件所说:
UITextView 类实现了可滚动的多行文本区域的行为”
因此,理想情况下,您不应将UILabel
对象添加到UITextView
. 相反,我会为您要显示的每篇文章创建一个UILabel
和一个:UITextView
UILabel *article1Label = [[UILabel alloc] initWithFrame:label1Frame];
UITextView *article1Text = [[UITextView alloc] initWithFrame:text1Frame];
UILabel *article2Label = [[UILabel alloc] initWithFrame:label2Frame];
UITextView *article2Text = [[UITextView alloc] initWithFrame:text2Frame];
...
如果您希望您的用户滚动并阅读所有文章,您可以将所有这些子视图添加到一个UIScrollView
对象:
UIScrollView *articlesScrollView = [[UIScrollView alloc] initWithFrame:scrollViewFrame];
[articlesScrollView addSubview:article1Label];
[articlesScrollView addSubview:article1Text];
[articlesScrollView addSubview:article2Label];
[articlesScrollView addSubview:article2Text];
最后,UIScrollView
通过添加子视图的所有高度来计算内容大小。例如:
CGFloat totalHeight = article1Text.frame.size.height + article2Text.frame.size.height;
articleScrollView.contentSize = {
.width = articleScrollView.bounds.size.width,
.height = totalHeight
};