Skip to content

ingocraft/LMCenteredCollectionView

Repository files navigation

LMCenteredCollectionView

Swift Version Cocoapods GitHub Cocoapods platforms

Introduction

LMCenteredCollectionView is a infinite scroll view.

Example

Usage

Create your cell,

class YourCell: LMCenteredCollectionViewCell {}

Then show centeredCollectionView in YourViewController,

class YourViewController: UIViewController {
    private var centeredCollectionView: LMCenteredCollectionView!
    
    override func viewDidLoad() {
        centeredCollectionView = LMCenteredCollectionView(frame: UIScreen.main.bounds, direction: .horizontal)
        centeredCollectionView.register(YourCell.self)
        view.addSubview(centeredCollectionView)
    }
}

You must implement dataSource to show your contents,

centeredCollectionView.dataSource = self

extension YourViewController: LMCenteredCollectionViewDataSource {
    func numberOfItems(in centeredCollectionView: LMCenteredCollectionView) -> Int {
        return 10
    }
    
    func centeredCollectionView(_ centeredCollectionView: LMCenteredCollectionView, cellForItemAt index: Int) -> LMCenteredCollectionViewCell {
        let cell = centeredCollectionView.dequeueReusableCell(for: index) as! YourCell
        return cell
    }
}

Implementing delegate if you want to resize items and spacing between items. The default size is (50, 50) and the interitemSpacing is 10.

For more control you can see LMCenteredCollectionViewDelegate for detail.

centeredCollectionView.delegate = self

extension YourViewController: LMCenteredCollectionViewDelegate {
    func sizeOfItems(in centeredCollectionView: LMCenteredCollectionView) -> CGSize {
        return CGSize(width: 50, height: 50)
    }
    
    func interitemSpacingBetweenItems(in centeredCollectionView: LMCenteredCollectionView) -> CGFloat {
        return 10
    }
}

Installation

CocoaPods

Add LMCenteredCollectionView in your Podfile.

pod 'LMCenteredCollectionView'

Then,

pod install

Manual

Copy Sources folder to your project. That's it.

Licence

The MIT License (MIT)

About

infinite, centered collection view.

Resources

License

Stars

Watchers

Forks

Packages

No packages published