When i am pasting the text in UITextView
then some extra space is getting added into it. But when i scroll it then the textView
is fitted according to the content. In textViewDidChange
, textView
height constraint is being set according to its content size. Anybody faced the same issue?
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
}
}
You have to set the textView's smartInsertDeleteType to .no
textView.smartInsertDeleteType = .no
Reference link: https://developer.apple.com/documentation/uikit/uitextinputtraits/2865828-smartinsertdeletetype
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.