views:

465

answers:

3

Hi Guys,

When i start typing text in a default textView in my viewcontroller, its 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 dont know what i can do? Anyone any ideas?

A: 

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
+1  A: 

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
+1  A: 

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);
Sam V
Thanks! this worked for me.
MattDiPasquale
I use both this technique and Aaron's here: http://github.com/acani/acani-chat/blob/master/Lovers/Classes/ChatViewController.mIt 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.
MattDiPasquale
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.
Sam V