I'm having a weird problem with iOS 10, Swift 3. The UITextView sometimes get "stuck". With "stuck" I mean the text inside of it gets cut, so only a part of it is visible. When this happens, the UITextView is not scrollable.
In the storyboard I have pinned it to the edges.
The code related to the view:
override func viewDidLoad() {
...
lyricsTextView.text = song.lyrics
lyricsTextView.font = UIFont(name: "Avenir-Roman", size: 15)
lyricsTextView.textAlignment = .center
...
override func viewDidLayoutSubviews() {
lyricsTextView.setContentOffset(CGPoint.zero, animated: false)
}
I had no issues with iOS 9, and it only occurs on my real device, not in the simulator.
Anyone experienced anything similar?
Thanks!
EDIT:
It now appeared in the simulator as well!
As explained in Large Text Being Cut Off in UITextView That is Inside UIScrollView try setting scroll = false and then back to =true after setting the text.
Swift 3:
textView.text = someText
textView.isScrollEnabled = false
textView.isScrollEnabled = true
An elegant solution is to use sizeToFit()
after the TextView has been setup.
Swift 5:
yourTextView.sizeToFit()
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