4

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!

atlas
  • 361
  • 4
  • 13
  • There must be a deep bug here, because I see the same thing in the Xcode interface itself! The Quick Help inspector, on the right, often can't be scrolled far enough to read the whole thing. I've filed a bug on that; I suggest you file a bug on this! (You might see whether the new Xcode 8.1 beta fixes this first, though.) – matt Sep 24 '16 at 17:31
  • I have experienced the same thing on iOS9 as well, it was totally inpredictable, even closing/opening the screen in the _same_ runtime session resolved it; I have found no permanent fix it yet, but in my case it appeared quite freuqently when I changed the layer's `sublayerTransform` value and set up a persepctive for the view – it might've been caused by something behind the scenes which I couldn't actually fix or change. mine also appeared only on the _real_ device, probably the 3D engines' implemenation are different on OSX and on iOS. – holex Sep 24 '16 at 18:01

2 Answers2

8

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
Community
  • 1
  • 1
muthusuba
  • 404
  • 5
  • 4
0

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

Swift 5:

yourTextView.sizeToFit()
Ben
  • 2,044
  • 3
  • 22
  • 38