Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView: disable scrolling, multiline enable [duplicate]

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

like image 856
DeyaEldeen Avatar asked Aug 02 '16 07:08

DeyaEldeen


2 Answers

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.

like image 153
DeyaEldeen Avatar answered Jan 03 '23 15:01

DeyaEldeen


In Storyboard / Interface Builder simply disable scrolling in the Attribute inspector.

In code textField.scrollEnabled = false should do the trick.

like image 34
Tum Avatar answered Jan 03 '23 16:01

Tum