IOS9 Multi-Line UITextView not displaying properly

I have an application that used UITextViews to display text (possibly multi-line) and worked correctly in iOS8. I disabled scrolling by declaring self.scrollEnabled = false . UITextView broke words to new lines where needed, and everything seemed to work!

However, when I ran the code on iOS9, the UITextView displayed only one line of text (no matter how many lines of text were).

enter image description here

I realized that when I deleted the line self.scrollEnabled = false , the UITextView displayed correctly (showing all the rows), but it became scrollable again, and that was not the intention.

enter image description here

What to do to allow a UITextView display multiple rows and disable scrolling? Has anyone seen this problem before or had any suggestions?

Thanks!

+5
source share
1 answer

You must set textContainerInset textView

The code below creates a UITextView with multiple lines (you must also set limits on the text view)

 let titleTextView: UITextView = { let textView = UITextView() textView.translatesAutoresizingMaskIntoConstraints = false textView.text = "something to say" textView.textContainerInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) textView.textColor = UIColor.lightGray textView.font = UIFont(name: "Helvetica", size: 14) return textView }() 
+1
source

Source: https://habr.com/ru/post/1234841/


All Articles