gpt4 book ai didi

ios - 无法将高度传递给scrollview.content 大小

转载 作者:行者123 更新时间:2023-11-29 04:33:53 24 4
gpt4 key购买 nike

我将 TextView 扩展到其内容大小,如下所示

CGRect _frame = descriptionText.frame;
_frame.size.height = descriptionText.contentSize.height;
descriptionText.frame = _frame;

内容超出了 View 范围,无法向下滚动查看文本。

我尝试像这样设置 ScrollView 的大小

scrollView.contentSize = CGSizeMake(295,_frame.size.height);

但它无法滚动,但如果我给出这样的数值,则可以工作

scrollView.contentSize = CGSizeMake(295,600);

我需要将 ScrollView 的大小设置为动态内容的大小。我怎样才能做到这一点?

编辑描述文字

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

最佳答案

这段改变大小的代码,必须在你将textview添加到 ScrollView 之后调用

此行之后

[scrollView addSubview: descriptionText];

您可以使用此分割

CGRect _frame = descriptionText.frame;
_frame.size.height = descriptionText.contentSize.height;
descriptionText.frame = _frame;

我刚刚测试了它,它有效

确保以下内容

  • 您是否正确地将 TextView 添加到 ScrollView
  • 报价不为零

关于ios - 无法将高度传递给scrollview.content 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11308943/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com