AMRefresher 1.0.0

AMRefresher 1.0.0

Maintained by [arturdev].




  • By
  • arturdev

AMRefresher

Super easy way to use "Pull To Refresh" and "Infinite Scrolling" with 1 line of code

Usage

Adding PullToRefresh and InfiniteScroll to any UIScrollView is pretty easy:

override func viewDidLoad() {
    super.viewDidLoad()

    //Adding Pull To Refresh
    tableView.am.addPullToRefresh { [unowned self] in
        //Do your heavy job.
        //modify your datasource
        //...
        self.tableView.reloadData() //or insert cells at top of tableView
        self.tableView.am.pullToRefreshView?.stopRefreshing()
    }
 
    //Adding Infinite Scrolling
    tableView.am.addInfiniteScrolling { [unowned self] in
        //Do your heavy job.
        //append to your datasource
        //...
        self.tableView.reloadData() //or insert cells at bottom of tableView
        self.tableView.am.infiniteScrollingView?.stopRefreshing()
    }
}

If you’d like to programmatically trigger the refresh (for instance in viewDidAppear:), you can do so with:

tableView.am.pullToRefreshView?.trigger()

Customization

Both AMPullToRefreshView and AMInfiniteScrollingView have public method

public func setCustomView(_ view: UIView, for state: AM.State)

So you can call this method and pass any UIView you want to show for each state.