0

I have a UITextView in UIViewController with auto layout:

enter image description here

The TextView size changes proportionally in accordance to the View (for example on rotation, or run on different dispositive iPhone 4s..6s).

Unfortunately the content text doesn't show from first line:

enter image description here

I suppose that the content inset is wrong but I don't have a solution.

JSON C11
  • 11,272
  • 7
  • 78
  • 65
giorgio83
  • 288
  • 2
  • 14
  • Can you post some code? – Gavin Hope Jan 31 '16 at 21:09
  • thanks for the support...i added the constraints in storyboard, my view size is 600 x 600 (any,any) I didn't write code , I used the sample text "Lorem ipsum..." repeated several times – giorgio83 Jan 31 '16 at 21:19
  • It's hard to say with the info you've given so far, and, without seeing the Interface Builder storyboard setup. Some more questions: *the content text doesn't show from first line* - do you mean, **only the first line is shown**? Or, **the top/first line of the text view is empty**? (or something else?) Also, is it only wrong in *some* conditions? Or is it always wrong? – Gavin Hope Jan 31 '16 at 21:36
  • 1
    i added any images, thanks – giorgio83 Jan 31 '16 at 21:51
  • Take a look at my comments in the answer... try deleting those constraints, and, for the screen shot of the app running, can the text scroll up and down? (when trying the scroll that's when you'll see the "scroll bars"). – Gavin Hope Jan 31 '16 at 22:06

2 Answers2

0

I don't use Interface Builder - so I'm sure someone can correct me if I'm wrong, or, see the mistake if I've missed it...

But, from your screen shot (resolution is a bit low) it looks like you've got vertical constraints when positioning the text view: there's a value showing a spacing between the view and Top Layout Guide (and again for the bottom layout guide). You could just delete these...

Specifically:

  • Top space to equals 135
  • Bottom space to equals 106

As for your second screen shot, I'm not sure if it's a different device to the image on the right... but maybe the sample text just doesn't fit in the view, and it's scrolled to the bottom of the text. That would make it look like the top text is cut off, because it's clipped by the top of the UITextView.

Gavin Hope
  • 2,173
  • 24
  • 38
  • i need these spaces (top, bottom).. and for the second screen shot is the same simulator: on the left my problem, on the right i scroll to top position manually – giorgio83 Jan 31 '16 at 22:15
  • Ok, so, in your second image, the one showing two screen shots of the app running... are those images two different devices? Is the device on the left smaller than the device on the right? If yes... then, the text is simply too big to fit in the `UITextView`, in which case it has scrolled down. You'll be able to scroll it up and down. **Note**: the size of the text won't automatically change for smaller/larger devices. So, the same text/content won't necessarily fit on one device, even if it fits on another... – Gavin Hope Jan 31 '16 at 22:18
0

I had the same problem, and I tried all of the work-arounds to setContentOffset and/or scrollRangeToVisible to no avail.

I was inspired by this SO post: https://stackoverflow.com/a/21287306/610550

I ended up disabling scrolling on the textView on the storyboard, and then using self.textView.scrollEnabled = true in viewDidLoad(). It worked perfectly!

Community
  • 1
  • 1
KidIcarus271
  • 144
  • 2
  • 9