VHCarrouselCollectionView is an horizontal UICollectionView written in Swift which loops infinitely.
Platform | Minimum Swift Version | Installation |
---|---|---|
iOS 10.0+ | 4.0 | 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"))
]
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()
}
}
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
}
}
VHCarrouselCollectionView is released under the MIT license. See LICENSE for details.
link |
Stars: 0 |
Last commit: 2 weeks ago |
Supporting SPM
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics