1

When I start typing text in a default textView in my viewcontroller, it's not going to the bottom of the textfield. It leaves room for 2 more lines of text and then starts scrolling. I want it to start scrolling when I start going beyond the last line.

I tried everything, and I don't know what I can do? Anyone any ideas?

Bart
  • 19,692
  • 7
  • 68
  • 77
Ton
  • 365
  • 4
  • 19

4 Answers4

1

as UITextView is a subclass of UIScrollView, look at UIScrollVIew's properties, like contentInset and others to see if they might be creating a gap between your frame/bounds and the content inside.

mahboudz
  • 39,196
  • 16
  • 97
  • 124
1

Just adding to what mahboudz already said. Here's some sample code that can be adjusted to get what you need:

    UIEdgeInsets contentInset = notes.contentInset;
    contentInset.bottom = 10.0;
    notes.contentInset = contentInset;

Where notes in this example is the UITextView.

Aaron
  • 868
  • 1
  • 8
  • 14
1

In addition to what mahboudz and Aaron said, I can confirm that UITextView does add some contentInset to the bottom, so I put the following code inside textView:shouldChangeTextInRange:replacementText: of UITextViewDelegate

textView.contentInset = UIEdgeInsetsMake(0, 0, 5, 0);
samvermette
  • 40,269
  • 27
  • 112
  • 144
  • I use both this technique and Aaron's here: http://github.com/acani/acani-chat/blob/master/Lovers/Classes/ChatViewController.m It autoscrolls nicer now, but it still adds the contentInset to the bottom when you get to the third line. Any ideas on how to prevent that? Run it and check out the console. – ma11hew28 Jul 25 '10 at 08:58
  • If you implement the right delegate method it should set the contentInset every time the textView content changes. NSLog the textView contentInset in this method to see if it gets set properly. – samvermette Jul 26 '10 at 03:43
0

When moving code from a nib to setting it up programmatically, I ran into a similar problem--wherever the insertion point was, it was scrolled up out of view. I eventually found that my UITextView had a bottom inset of 32 pixels when I created it programmatically, though I'm not sure why. So I fixed it by setting the contentInset when I create the text view:

textView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
Christopher Pickslay
  • 17,523
  • 6
  • 79
  • 92