我正在将文字视图扩展为其内容大小,如下所示
CGRect _frame = descriptionText.frame;
_frame.size.height = descriptionText.contentSize.height;
descriptionText.frame = _frame;
且内容超出了视图,无法向下滚动以查看文字。
我尝试像这样设置滚动视图的大小
scrollView.contentSize = CGSizeMake(295,_frame.size.height);
但它无法滚动,但如果我给出像这样的数值
,则有效scrollView.contentSize = CGSizeMake(295,600);
我需要将滚动视图的大小设置为动态内容的大小。 我怎样才能做到这一点?
修改 说明文字
CGRect descriptionTextViewRect = CGRectMake(15, 185, 280, 85);
descriptionText = [[UITextView alloc] initWithFrame:descriptionTextViewRect];
descriptionText.textAlignment = UITextAlignmentLeft;
descriptionText.text =offerdes;//this is the text fetched from an xml and is dynamic.
descriptionText.editable = NO;
descriptionText.layer.cornerRadius = 5.0;
descriptionText.clipsToBounds = YES;
descriptionText.userInteractionEnabled = YES;
descriptionText.font = [UIFont systemFontOfSize:15];
[scrollView addSubview: descriptionText];
[descriptionText release];
答案 0 :(得分:1)
在您将文本视图添加到滚动视图后调用此代码段以更改大小必须
这一行之后
[scrollView addSubview: descriptionText];
您可以使用此细分
CGRect _frame = descriptionText.frame;
_frame.size.height = descriptionText.contentSize.height;
descriptionText.frame = _frame;
我刚测试过它并且有效
确保以下
答案 1 :(得分:0)
问题不在于您设置大小的方式,而是存储框架的变量设置不正确。
您需要查看代码中的其他位置,以跟踪descriptionText.contentSize返回CGSizeZero的原因。