I want that if user add text and it add new line it should increase height and if user delete soometext and some line than it should decrease its height
For this I'have tried below solution
func textViewDidChange(_ textView: UITextView) {
self.updateCharacterCount()
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(4),
execute: {
let pos = textView.endOfDocument
self.referenceOfClass?.textOfTextViewForTitle =
self.title_Name.text
let currentRect = textView.caretRect(for: pos ??
UITextPosition.init())
if (currentRect.origin.y == -1 || currentRect.origin.y ==
CGFloat.infinity){
if let val = self.indexPath{
self.referenceOfClass?.previousRectforTitle = currentRect
self.referenceOfClass?.inq_Tableview.reloadRows(at:
[val], with: .automatic)
}
}
else if currentRect.origin.y <
self.referenceOfClass?.previousRectforTitle.origin.y ?? 0.0 {
if let val = self.indexPath{
self.referenceOfClass?.previousRectforTitle = currentRect
self.referenceOfClass?.inq_Tableview.reloadRows(at:
[val], with: .automatic)
}
}
})
}
but it is not working in this textView.caretRect(for: pos ?? UITextPosition.init()) always return same value (0,-1)
So how can I solve this?
I am using xcode10.1 and this textview is in tableviewcell