Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a scroll view scrolled in bottom or not in ios [duplicate]

How to check if a scroll view has been scrolled to the bottom of the screen in iOS? Thanks in advance.

like image 524
Rafay Avatar asked Dec 16 '25 11:12

Rafay


2 Answers

implement UIScrollViewDelegate in the class that hosts UIScrollView.

set the scrollView.delegate property.

implement below method.

-(void)scrollViewDidScroll: (UIScrollView*)scrollView
{
    float scrollViewHeight = scrollView.frame.size.height;
    float scrollContentSizeHeight = scrollView.contentSize.height;
    float scrollOffset = scrollView.contentOffset.y;

    if (scrollOffset + scrollViewHeight == scrollContentSizeHeight)
    {
        //This condition will be true when scrollview will reach to bottom
    }

}
like image 68
2intor Avatar answered Dec 19 '25 07:12

2intor


Implement the scrollview delegate and write below code into it.

- (void)scrollViewDidScroll:(UIScrollView *)aScrollView {
    CGPoint offset = aScrollView.contentOffset;
    CGRect bounds = aScrollView.bounds;
    CGSize size = aScrollView.contentSize;
    UIEdgeInsets inset = aScrollView.contentInset;
    float y = offset.y + bounds.size.height - inset.bottom;
    float h = size.height;

    if(y >= h) {
        NSLog(@"At the bottom...");
    }
}
like image 36
Apurv Avatar answered Dec 19 '25 06:12

Apurv