2

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.

Print's

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:

Constraint's

buczek
  • 2,011
  • 7
  • 29
  • 40
Lucas Paim
  • 417
  • 4
  • 13

3 Answers3

1

Try to add textView.layer.masksToBounds = true.

Max Pevsner
  • 4,098
  • 2
  • 18
  • 32
0

Try to set textView.clipsToBounds = true

Kubba
  • 3,390
  • 19
  • 34
0

Add this code in textViewDidBeginEditing delegate. It is work for me.

textView.contentInset = UIEdgeInsetsZero;

in viewDidload

[textView setClipsToBounds:YES];
Yogesh More
  • 239
  • 3
  • 4