Lucas Paim
Lucas Paim

Reputation: 495

UITextView the text is going out of the box

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

Upvotes: 2

Views: 1270

Answers (3)

Yogesh More
Yogesh More

Reputation: 239

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

textView.contentInset = UIEdgeInsetsZero;

in viewDidload

[textView setClipsToBounds:YES];

Upvotes: 0

Kubba
Kubba

Reputation: 3438

Try to set textView.clipsToBounds = true

Upvotes: 0

Max Pevsner
Max Pevsner

Reputation: 4094

Try to add textView.layer.masksToBounds = true.

Upvotes: 1

Related Questions