Ios UIScrollView大小与UITextView大小匹配
我有一个Ios UIScrollView大小与UITextView大小匹配,ios,objective-c,uiscrollview,uitextview,Ios,Objective C,Uiscrollview,Uitextview,我有一个UIScrollView,在UITextView中有一块文本。文本可以是来自服务器的任意数量的单词 我希望滚动视图的大小与UITextView的大小相匹配 目前的做法是什么 截图: 您可以使用下面的方法获取文本视图的高度 CGSize size = [@"Your string" sizeWithFont:[UIFont fontWithName:@"TimesNewRomanPS-BoldMT" size:22] constrainedT
UIScrollView
,在UITextView
中有一块文本。文本可以是来自服务器的任意数量的单词
我希望滚动视图的大小与UITextView
的大小相匹配
目前的做法是什么
截图:
您可以使用下面的方法获取文本视图的高度
CGSize size = [@"Your string"
sizeWithFont:[UIFont fontWithName:@"TimesNewRomanPS-BoldMT" size:22]
constrainedToSize:CGSizeMake(500, CGFLOAT_MAX)];
_textView.frame = CGRectMake(x,y, width, size.height);
_scrollview.frame = CGRectMake(x,y, width, size.height);
或者你可以使用一个小技巧:p
使用标签获取文本视图的高度
UILabel *tempLabel = [[UILabel alloc]initWithFrmae:_textView.bounds];
tempLabel.numberOfLines = 0; // Important to do
tempLabel.text = @"Your Text";
[tempLabel sizeToFit]; // This will resize your Label and now you can use it's height to manage your textView.
现在使用这个模板的高度
tempLabel.frame.size.height
您可以使用下面的方法来获取textview的高度
CGSize size = [@"Your string"
sizeWithFont:[UIFont fontWithName:@"TimesNewRomanPS-BoldMT" size:22]
constrainedToSize:CGSizeMake(500, CGFLOAT_MAX)];
_textView.frame = CGRectMake(x,y, width, size.height);
_scrollview.frame = CGRectMake(x,y, width, size.height);
或者你可以使用一个小技巧:p
使用标签获取文本视图的高度
UILabel *tempLabel = [[UILabel alloc]initWithFrmae:_textView.bounds];
tempLabel.numberOfLines = 0; // Important to do
tempLabel.text = @"Your Text";
[tempLabel sizeToFit]; // This will resize your Label and now you can use it's height to manage your textView.
现在使用这个模板的高度
tempLabel.frame.size.height
您可以使用下面的方法来获取textview的高度
CGSize size = [@"Your string"
sizeWithFont:[UIFont fontWithName:@"TimesNewRomanPS-BoldMT" size:22]
constrainedToSize:CGSizeMake(500, CGFLOAT_MAX)];
_textView.frame = CGRectMake(x,y, width, size.height);
_scrollview.frame = CGRectMake(x,y, width, size.height);
或者你可以使用一个小技巧:p
使用标签获取文本视图的高度
UILabel *tempLabel = [[UILabel alloc]initWithFrmae:_textView.bounds];
tempLabel.numberOfLines = 0; // Important to do
tempLabel.text = @"Your Text";
[tempLabel sizeToFit]; // This will resize your Label and now you can use it's height to manage your textView.
现在使用这个模板的高度
tempLabel.frame.size.height
您可以使用下面的方法来获取textview的高度
CGSize size = [@"Your string"
sizeWithFont:[UIFont fontWithName:@"TimesNewRomanPS-BoldMT" size:22]
constrainedToSize:CGSizeMake(500, CGFLOAT_MAX)];
_textView.frame = CGRectMake(x,y, width, size.height);
_scrollview.frame = CGRectMake(x,y, width, size.height);
或者你可以使用一个小技巧:p
使用标签获取文本视图的高度
UILabel *tempLabel = [[UILabel alloc]initWithFrmae:_textView.bounds];
tempLabel.numberOfLines = 0; // Important to do
tempLabel.text = @"Your Text";
[tempLabel sizeToFit]; // This will resize your Label and now you can use it's height to manage your textView.
现在使用这个模板的高度
tempLabel.frame.size.height
UITextView是UIScrollView的扩展。因此,您可以使用contentSize属性获取其内容大小。UITextView是UIScrollView的扩展。因此,您可以使用contentSize属性获取其内容大小。UITextView是UIScrollView的扩展。因此,您可以使用contentSize属性获取其内容大小。UITextView是UIScrollView的扩展。因此,您可以使用contentSize属性获取其内容大小。UITextView有自己的滚动,为什么要将其放置在UIScrollView上我知道,但是客户端需要一个大的滚动视图。您可以创建具有动态高度的
uilabel
,并将该高度赋予uiscrollview
。UITextView有自己的滚动视图,为什么要将其放在uiscrollview上我知道,但是客户端需要一个大的滚动视图。您可以创建具有动态高度的uilabel
,并将该高度赋予uiscrollview
。UITextView有自己的滚动视图,为什么要将其放在uiscrollview上我知道,但是客户端需要一个大的滚动视图。您可以创建具有动态高度的uilabel
,并将该高度赋予uiscrollview
。UITextView有自己的滚动视图,为什么要将其放在uiscrollview上我知道,但是客户端需要一个大的滚动视图。您可以创建具有动态高度的uilabel
,并将该高度赋予uiscrollview
。这很聪明很聪明很聪明很聪明很聪明很聪明