Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView text get cut off - iOS 10

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!

like image 390
atlas Avatar asked Feb 07 '23 01:02

atlas


2 Answers

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
like image 104
muthusuba Avatar answered Feb 13 '23 05:02

muthusuba


An elegant solution is to use sizeToFit() after the TextView has been setup.

Swift 5:

yourTextView.sizeToFit()
like image 27
Ben Avatar answered Feb 13 '23 07:02

Ben