atlas
atlas

Reputation: 411

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!

Upvotes: 4

Views: 4165

Answers (2)

Ben
Ben

Reputation: 3804

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

Swift 5:

yourTextView.sizeToFit()

Upvotes: 2

muthusuba
muthusuba

Reputation: 474

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

Upvotes: 8

Related Questions