how to make UITextView height dynamic according to text length?
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
Solution 1:
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
.
Solution 2:
In Storyboard / Interface Builder simply disable scrolling in the Attribute inspector.
In code textField.scrollEnabled = false
should do the trick.
Solution 3:
All I had to do was:
- Set the constraints to the top, left, and right of the textView.
- Disable scrolling in Storyboard.
This allows autolayout to dynamically size the textView based on its content.