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
It can be done using the UITextView contentSize . This will not work if auto layout is ON. With auto layout, the general approach is to use the sizeThatFits method and update the constant value on a height constraint. CGSize sizeThatShouldFitTheContent = [_textView sizeThatFits:_textView.
Step 1 : Click the Attribute Inspector, Select the Border Styles which is not the rounded one. Step 2 : Now go to Size Inspector and change the size of the TextField. Step 3 : Create an @IBOutlet for TextField and then add below code inside the viewWillAppear() or viewDidAppear() .
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
.
In Storyboard / Interface Builder simply disable scrolling in the Attribute inspector.
In code textField.scrollEnabled = false
should do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With