Home > OS >  [IOS]how to scroll to the bottom when there is a lot of content
[IOS]how to scroll to the bottom when there is a lot of content

Time:07-09

When the content is relatively small, the following code works well

CGPoint bottomOffset = CGPointMake(0, self.textView.contentSize.height - self.textView.bounds.size.height   self.textView.contentInset.bottom);
NSLog(@"%f",bottomOffset.y);
[self.textView setContentOffset:bottomOffset animated:YES];

But when there is a lot of content, it only scrolls to half the position. What I understand is that because it has too much content, it doesn't load everything at one time. When sliding, it loads the following content, which makes it impossible to scroll to the bottom with the above code, so how can I make it load all the content at one time, or what other way can I make it scroll to the bottom

CodePudding user response:

You can use the following code to scroll to the las character of the text:

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