Take the 2-minute tour ×

i have an uiview and i add a editable UITextView to it

UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(5, 5, 219, 47)];
[self addSubview:textView];
textView.font = [UIFont systemFontOfSize:14];

when i type it doesn't go down automatic. anybody got an idea?

share|improve this question
add comment

5 Answers

Just figured out that you must use a length > 0. Ie

NSRange range = NSMakeRange(textView.text.length - 1, 1);
[textView scrollRangeToVisible:range];

Worked for me anyway.

share|improve this answer
Thanks, this was helpful. You also need to check if textView.text.length > 0. –  Z S Apr 10 '10 at 18:21
Note that this will cause the textView to scroll to the bottom. It's not a great idea to put this in UITextView's textViewDidChange: delegate; if you are editing at the top of the textview, it'll get scrolled to the bottom, which is not what the user would expect. –  Z S Apr 18 at 1:53
add comment

To scroll to the end of the buffer I tried

[textView scrollRangeToVisible:NSMakeRange([textView.text length]-1, 1)];

But nothing happened. Instead this works

textView.selectedRange = NSMakeRange(textView.text.length - 1, 0);
share|improve this answer
add comment

I think you'll have to do

[textView scrollRangeToVisible:[textView selectedRange]];

in textDidChange.

share|improve this answer
nope that does not do anything –  Andy Jacobs Feb 9 '09 at 14:38
hmm, strange. can you try [textView scrollRangeToVisible:NSMakeRange(textView.text.length, 0)]; –  Can Berk Güder Feb 9 '09 at 15:30
doesn't work either –  Andy Jacobs Feb 9 '09 at 15:54
This is working perfect for me. –  CRDave Oct 19 '13 at 7:06
add comment
up vote 0 down vote accepted

if found a solution

i put the textview into a view and set the view to clipToBounds = YES then i put the textView to a height of 70

that fixed the problem.

very strange solution, but it finally works :)

share|improve this answer
If 70 is lower than your UITextView's original height then it gets clipped to that value an probably by coincidence this is exactly what it takes for your case to "autoscroll" to the last line. It's a little too hackish :) –  Mihai Damian Nov 27 '09 at 14:41
add comment

This works:

- (void)textViewDidChange:(UITextView *)textView {
    if (_moveToBottom) {
        int y = textView.contentSize.height - textView.frameHeight + self.textView.contentInset.bottom + self.textView.contentInset.top;
        if(y > 0) {
            [textView setContentOffset:CGPointMake(0, y) animated:YES];
        _moveToBottom = NO;
    else {

    if ([text isEqualToString:@"\n"] && range.location == [textView.text length]) {
        _moveToBottom = YES;
    return YES;
share|improve this answer
add comment

Your Answer


