Reputation: 495
I am working on a chat app. The message box resizes according to the length of the text, but the text is going out of the box when the line breaks.
I tried adding textView.contentInset = UIEdgeInsetsZero
in textViewDidChange
method, but it continues to not work.
The function:
func textViewDidChange(textView: UITextView) {
let minSize = CGFloat(50)
let maxSize = UIScreen.mainScreen().bounds.height - 50 - keyboardHeight
let expectedSize = textView.contentSize.height + 9
var newSize = expectedSize < minSize ? minSize : expectedSize
newSize = newSize > maxSize ? maxSize : newSize
acessoryViewH.constant = newSize
textView.contentInset = UIEdgeInsetsZero
}
The auto-layout constraints:
Upvotes: 2
Views: 1270
Reputation: 239
Add this code in textViewDidBeginEditing delegate. It is work for me.
textView.contentInset = UIEdgeInsetsZero;
in viewDidload
[textView setClipsToBounds:YES];
Upvotes: 0