Latest 2.0.1
Homepage https://github.com/Gini-Apps/GAInfiniteCollectionKit-iOS
License MIT
Platforms ios 9.0
Frameworks UIKit
Authors

Markdownify

GAInfiniteCollectionKit-iOS

Give your collection view the infinite scrolling behavior.

SponsorVersionAuthorSwiftSwift

GAInfiniteCollectionKit-iOS

GAInfiniteCollectionKit-iOS

Table of Contents

  1. Requirements
  2. Installation
  3. How to Use
  4. Advanced uses

Requirements:

  • iOS 9.0+
  • Xcode 9.4+
  • Swift 4.1+

Installation:

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate GAInfiniteCollectionKit-iOS into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
  pod 'GAInfiniteCollectionKit-iOS'
end

Then, run the following command:

$ pod install

How to Use:

Step one:

Create instance of InfiniteScrollingBehavior and set the collection view
delgate and dataSource to the InfiniteScrollingBehavior instance,
The infinite Scrolling will work only if the numner of item is bigger then the frame of the collection view

Example:

infiniteScrollingBehavior   = InfiniteScrollingBehavior(collectionView: collectionView, dataSource: self, delegate: self, forceInfinite: false)
collectionView.delegate     = infiniteScrollingBehavior
collectionView.dataSource   = infiniteScrollingBehavior

Step two:

Implement the protocols InfiniteScrollingBehaviorDataSource and InfiniteScrollingBehaviorDelegate

Example:

// MARK: - InfiniteScrollingBehaviorDataSource
extension MyObject : GAInfiniteScrollingBehaviorDataSource
{
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath, withIndexForItem itemIndex: Int) -> UICollectionViewCell
    {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellID", for: indexPath)

        configor(cell: cell, in: itemIndex)
        return cell
    }

    func numberOfItems() -> Int
    {
        return array.count
    }
}

// MARK: - InfiniteScrollingBehaviorDelegate
extension MyObject : GAInfiniteScrollingBehaviorDelegate
{
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
    {
    }

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
    {
        return CGSize(width: 150, height: 50)
    }

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat
    {
        return 10
    }

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat
    {
        return 10
    }
}

Advance Uses:

forceInfinite:

To force infinite Scrolling pass true in the constructor of the InfiniteScrollingBehavior.

Example:

infiniteScrollingBehavior   = InfiniteScrollingBehavior(collectionView: collectionView, dataSource: self, delegate: self, forceInfinite: true)

Latest podspec

{
    "name": "GAInfiniteCollectionKit-iOS",
    "version": "2.0.1",
    "summary": "Add infinite scrolling to UICollectionView",
    "description": "Add infinite scrolling to UICollectionView.",
    "homepage": "https://github.com/Gini-Apps/GAInfiniteCollectionKit-iOS",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "idoMeirov": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Gini-Apps/GAInfiniteCollectionKit-iOS.git",
        "tag": "2.0.1"
    },
    "swift_version": "4.2",
    "frameworks": "UIKit",
    "platforms": {
        "ios": "9.0"
    },
    "source_files": "GAInfiniteCollectionKit-iOS/Classes/**/*"
}

Pin It on Pinterest

Share This