![](/img/trans.png)
[英]How to remove extra space from the top and bottom of the UITextview in iOS?
[英]Extra space is added at the bottom of text in uitextview when string is pasted into it
当我在UITextView
粘贴文本时,会在其中添加一些额外的空间。 但是当我滚动它时,文本textView
会根据内容进行安装。 在textViewDidChange
,根据其内容大小设置textView
高度约束。 有人遇到过同样的问题吗?
func textViewDidChange(_ textView: UITextView) {
let newSize = textView.sizeThatFits(CGSize.init(width: textView.frame.size.width, height: CGFloat(MAXFLOAT)))
textView.isScrollEnabled = false
if newSize.height < 37 {
self.messageTextViewHeightConstraint.constant = minimumTextviewHeight
}
if (newSize.height >= 37 && newSize.height <= 100) {
self.messageTextViewHeightConstraint.constant = newSize.height
}
if (newSize.height >= 100) {
self.messageTextViewHeightConstraint.constant = maximumTextviewHeight
self.textView.isScrollEnabled = true
}
}
您必须将 textView 的 smartInsertDeleteType 设置为 .no
textView.smartInsertDeleteType = .no
参考链接: https : //developer.apple.com/documentation/uikit/uitextinputtraits/2865828-smartinsertdeletetype
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.