UITextView contentSize.height 比需要的大吗?
即使所有文本都适合其框架,UITextView
也会滚动。它滚动起来,好像文本底部有两行新行,但实际上并没有。因此,它的 contentSize.height
似乎比文本大几行。我该如何摆脱这个?即,如何收紧内容大小?
UITextView
scrolls even when all the text fits within its frame. It scrolls as if there are two new lines at the bottom of the text, but there aren't. So, its contentSize.height
seems to be a couple lines larger than the text. How do I get rid of this? I.e., how do I tighten up the content size?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以设置该 UITextView 的 contentSize,使其紧贴文本。
您可以使用名为 sizeWithFont 的 NSString 方法...您可以在此处查看完整列表: http://developer.apple.com/library/ios/#documentation/uikit/reference/NSString_UIKit_Additions/Reference/Reference.html
我注意到其中一些的一些问题,但永远不会让我失望的是:
我想你有一个固定的宽度并想找出正确的高度。考虑固定的 200px 宽度,它会是这样的:
考虑到你的 UITextView 在所有方向上都有 8px 的填充,所以如果你的 UITextView 框架是 200 宽度,你实际上会有 184px 的文本宽度。
You can set up the contentSize for that UITextView so that it tightens to the text.
You can make use of NSString methods named sizeWithFont.... You can check full list here: http://developer.apple.com/library/ios/#documentation/uikit/reference/NSString_UIKit_Additions/Reference/Reference.html
I've noticed some issues working with some of them, but one that never fails me is:
I suppose you have a fixed width and want to find out the correct height. Considering a fixed 200px width, it would be something like:
Take into consideration that your UITextView has an 8px padding in all directions, so if your UITextView frame is 200 width, you would actualy have a 184px width for text.
虽然已经晚了,但对其他人来说,请尝试:
这对我来说是工作。
It's late but, for other people, try with:
That's work for me.