Swiftpack.co - vidalhara/VHCarrouselCollectionView as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by vidalhara.
vidalhara/VHCarrouselCollectionView 1.0.0
Carrousel UICollectionView
⭐️ 0
🕓 2 weeks ago
iOS
.package(url: "https://github.com/vidalhara/VHCarrouselCollectionView.git", from: "1.0.0")

VHCarrouselCollectionView

Swift Platforms Swift Package Manager

VHCarrouselCollectionView is an horizontal UICollectionView written in Swift which loops infinitely.

Features

Requirements

Platform Minimum Swift Version Installation
iOS 10.0+ 4.0 Swift Package Manager

Installation

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

Once you have your Swift package set up, adding VHCarrouselCollectionView as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/vidalhara/VHCarrouselCollectionView.git", .upToNextMajor(from: "1.0.0"))
]

Usage

You should call following functions in order to work your carrousel.

@IBOutlet weak var collectionView: VHCarrouselCollectionView!

extension ViewController: UICollectionViewDelegate {
    func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
        collectionView.scrollViewWillBeginDragging()
    }

    func scrollViewWillEndDragging(
        _ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>
    ) {
        collectionView.scrollViewWillEndDragging(with: velocity, targetContentOffset: targetContentOffset)
    }

    func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
        collectionView.scrollViewDidEndScrollingAnimation()
    }
}

Configure Example

let source: [UIColor] = [.purple, .green, .blue]

collectionView.delegate = self
collectionView.dataSource = self
collectionView.carrouselDelegate = self
collectionView.sourceMultiplier = .triple

collectionView.configureTimer(interval: 2, animated: true)
collectionView.enableTimer()

extension ViewController: VHCarrouselCollectionViewDelegate {
    func vhCarrouselView(
        _ carrouselView: VHCarrouselCollectionView, centeredSourceIndexPath sourceIndexPath: IndexPath
    ) {
        debugPrint("\(sourceIndexPath.item)")
    }
}

extension ViewController: UICollectionViewDataSource {

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return source.count
    }

    func collectionView(
        _ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath
    ) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! LocalCVC
        let sourceIndex = indexPath.vhCarrouselSourceIndexPath(for: collectionView).item
        cell.backgroundColor = source[sourceIndex]
        return cell
    }
}

extension ViewController: UICollectionViewDelegateFlowLayout {

    func collectionView(
        _ collectionView: UICollectionView,
        layout collectionViewLayout: UICollectionViewLayout,
        sizeForItemAt indexPath: IndexPath
    ) -> CGSize {
        return .init(width: collectionView.frame.width * 0.8, height: collectionView.frame.height)
    }

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

License

VHCarrouselCollectionView is released under the MIT license. See LICENSE for details.

GitHub

link
Stars: 0
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

VHCarrouselCollectionView v1.0.0
2 weeks ago

Supporting SPM

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics