Skip to content

Instantly share code, notes, and snippets.

@Abeansits
Created January 8, 2014 14:27
Show Gist options
  • Select an option

  • Save Abeansits/8317545 to your computer and use it in GitHub Desktop.

Select an option

Save Abeansits/8317545 to your computer and use it in GitHub Desktop.

Revisions

  1. Abeansits created this gist Jan 8, 2014.
    14 changes: 14 additions & 0 deletions UIScrollView+Extensions.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    //
    // UIScrollView+Extensions.h
    //
    //

    @interface UIScrollView (Extensions)

    /// Returns true if the content has been scrolled all the way to the top (by pulling the content up).
    - (BOOL)isScrolledToTop;

    /// Returns true if the content has been scrolled all the way to the bottom (by pulling the content down).
    - (BOOL)isScrolledToBottom;

    @end
    32 changes: 32 additions & 0 deletions UIScrollView+Extensions.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    //
    // UIScrollView+Extensions.m
    //
    //

    #import "UIScrollView+Extensions.h"

    @implementation UIScrollView (Extensions)


    - (BOOL)isScrolledToTop {
    return (self.contentOffset.y <= [self verticalOffsetToTop]);
    }

    - (BOOL)isScrolledToBottom {
    return (self.contentOffset.y >= [self verticalOffsetToBottom]);
    }


    #pragma mark - Utils

    - (CGFloat)verticalOffsetToTop {
    CGFloat verticalOffsetTop = self.contentInset.top;
    return -verticalOffsetTop;
    }

    - (CGFloat)verticalOffsetToBottom {
    CGFloat verticalOffsetBottom = (self.contentSize.height + self.contentInset.bottom - self.bounds.size.height);
    return verticalOffsetBottom;
    }

    @end