Infinite Scroll in collectionView swift programmatically

https://github.com/pronebird/UIScrollView-InfiniteScroll

 

Download this code and Follow following steps to set infinite scroll in your collectionview.

Step: 1

Add following files in your project.

  • CustomInfiniteIndicator.swift
  • UIScrollView+InfiniteScroll.h
  • UIScrollView+InfiniteScroll.m

 

Step: 2

Add following line in your bridging header

 
#import "UIScrollView+InfiniteScroll.h"

Step: 3

now add following line in your viewDidLoad()

 Collectionview.infiniteScrollIndicatorView = CustomInfiniteIndicator(frame: CGRect(x: 0, y: 0, width: 24, height: 24))

 Collectionview.infiniteScrollIndicatorMargin = 40
Collectionview.addInfiniteScroll { [weak self] (scrollView) -> Void in
            self?.performFetch({
                scrollView.finishInfiniteScroll()
            })
        }

Step: 4

Now add following method in your viewController

fileprivate func performFetch(_ completionHandler: (() -> Void)?) {
        fetchData()
    }

Step: 5

set viewcontroller extention

extension ViewController {

    func fetchData() {
        print("fetchresult")
        // Set your code 
        self.page = self.page + 1
        self.ProductListAPI(page: page)
    }
}

Step: 6

Using following line you can stop loading

self.Collectionview.finishInfiniteScroll()