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).
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.
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!
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
}()
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