how to make UITextView height dynamic according to text length?

DeyaEldeen picture DeyaEldeen · Aug 2, 2016 · Viewed 102.7k times · Source

As you can see in this image

the UITextView changes it's height according to the text length, I want to make it adjust it's height according to the text length.

*I saw other questions, but solutions there didn't work for me

example

Answer

DeyaEldeen picture DeyaEldeen · Aug 2, 2016

this Works for me, all other solutions didn't.

func adjustUITextViewHeight(arg : UITextView)
{
    arg.translatesAutoresizingMaskIntoConstraints = true
    arg.sizeToFit()
    arg.scrollEnabled = false
}

In Swift 4 the syntax of arg.scrollEnabled = false has changed to arg.isScrollEnabled = false.