Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS9 Multi-Line UITextView not displaying properly

I have an app that was using UITextViews to display text (possibly multi-line), and was working correctly in iOS8. I turned off scrolling by declaring self.scrollEnabled = false. The UITextView would break words to new lines where needed and all seemed to be working!

However, when I ran the code on iOS9, the UITextView would only display 1 line of text always (no matter how many lines of text there were).

enter image description here

I realized when I removed the self.scrollEnabled = false line, the UITextView rendered correctly (showing all lines), but it was back to being scrollable obviously and this was not the intention.

enter image description here

What should I do to allow the UITextView to render multiple lines AND turn off scrolling? Has anybody seen this issue before or have any suggestions?

Thanks!

like image 871
Alex Avatar asked Oct 30 '15 05:10

Alex


1 Answers

You should set the textContainerInset of the textView

The code below creates a UITextView with multiple lines (you should also set constraints to the textview)

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
}()
like image 119
George Vardikos Avatar answered Sep 22 '22 10:09

George Vardikos