Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save novalagung/f303b4741a9a718ce047aa7d31d6df99 to your computer and use it in GitHub Desktop.
Save novalagung/f303b4741a9a718ce047aa7d31d6df99 to your computer and use it in GitHub Desktop.
make UITextView height dynamically follow it's content even with Auto Layout enabled

The key to make text view height follow it's content is by NOT SET HEIGHT CONSTRAINT and DISABLE THE SCROLL.

theTextView.isScrollEnabled = false
theTextView.text = "some text"
theTextView.sizeToFit()

But, if you already set the height constraint, then make it inactive

theTextViewHeightConstraint.isActive = false

theTextView.isScrollEnabled = false
theTextView.text = "some text"
theTextView.sizeToFit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment