Scroll UITextView To Bottom Scroll UITextView To Bottom ios ios

Scroll UITextView To Bottom


You can use the following code if you are talking about UITextView:

-(void)scrollTextViewToBottom:(UITextView *)textView {     if(textView.text.length > 0 ) {        NSRange bottom = NSMakeRange(textView.text.length -1, 1);        [textView scrollRangeToVisible:bottom];     }}

SWIFT 4:

func scrollTextViewToBottom(textView: UITextView) {    if textView.text.count > 0 {        let location = textView.text.count - 1        let bottom = NSMakeRange(location, 1)        textView.scrollRangeToVisible(bottom)    }}


Try this if you have problem on iOS 7 or above. See this SO answer.

- (void)scrollTextViewToBottom:(UITextView *)textView {    NSRange range = NSMakeRange(textView.text.length, 0);    [textView scrollRangeToVisible:range];    // an iOS bug, see https://stackoverflow.com/a/20989956/971070    [textView setScrollEnabled:NO];    [textView setScrollEnabled:YES];}


With Swift 3

let bottom = self.textView.contentSize.height - self.textView.bounds.size.heightself.textView.setContentOffset(CGPoint(x: 0, y: bottom), animated: true)