[英]How to resize the width of the UITextView according the?
我想问一下如何调整UITextView
大小以适合将显示在屏幕上的文本。
例如
将UITextView
调整为
谁能帮助我或给我一些建议。 谢谢
提示:
我尝试过sizeWithFont:constrainedToSize:
不起作用
如果您需要了解CGSize
是采取您NSString
如果在一行渲染,使用CGSize sz = [textView.text sizeWithFont:_textView.font]
再给予这个大小值调整框架。
如果您需要知道多行呈现时文本的size
,如果文本达到给定的宽度则将其包装,请使用sizeWithFont:constrainedToSize:lineBreakMode:
等。
前段时间我遇到了同样的问题(但是具有UITextView
的高度 ),并且我创建了一个CGRect
,其大小适合UITextView
的contentSize
,请尝试下面的代码
// assuming that you have a UITextView named textView with some text on it
CGRect textFrame = self.textView.frame;
textFrame.size.width = self.textView.contentSize.width;
self.textView.frame = textFrame;
试试这个对我有用的
CGRect frame = _textView.frame;
frame.size.height = _textView.contentSize.height;
frame.size.width = _textView.contentSize.width;
_textView.frame = frame;
快乐的编码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.