如何删除UITextView最后一个空行?
由于某种原因,UITextView 在末尾生成一个空行,这导致当文本实际上完全适合边界时它可以滚动以进行无意义的操作。
我发现 UITextView 的 contentView 中文本底部添加的额外空间几乎就是字体大小。所以它是一个额外的文本行。
我想删除该行,以便 UITextView 在没有理由滚动时不可滚动。
editable
设置为 NO。
我尝试设置 contentSize 属性以降低高度,但这没有效果。
字符串末尾没有空格或返回字符。它来自 UITextView。使用许多不同的字符串进行了测试。
For some reason, UITextView produces an empty line at the end which causes it to be scrollable for nonsense when the text actually fits perfectly into the bounds.
I figured out that this additional space added to the bottom of the text in the contentView of UITextView is almost exactly the font size. So it is an additional line of text.
I want to remove that line so the UITextView is not scrollable when there is no reason to scroll.
editable
is set to NO.
I tried setting the contentSize property with a reduced height but this has no effect.
The string has no whitespace or return character at the end. It comes from UITextView. Tested with a lot of different strings.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试更改
contentInset
属性并将底部插图设置为-10
。我个人认为这将是一个黑客,但当我测试它时它起作用了,所以只需检查正确的插图是什么。You can try altering the
contentInset
property and set the bottom inset to-10
. I personally think it would be a hack but it worked when I tested it so just check what the correct inset would be.