LastManifoldInfiniteCarousel is @IBDesignable extension to UIView you can easily create an infinite carousel from your views. Works with at least three views.
LastManifoldInfiniteCarousel is available through Carthage. To install just write into your Cartfile:
github "LastManifold/LastManifoldInfiniteCarousel"
Create UIView in your .nib or .storyboard file, and add
LMInfiniteCarouselas class.
Connect outlet to View Controller
@IBOutlet weak var infiniteCarousel: LMInfiniteCarousel!In ViewDidAppear load your slides.
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
guard let view1 = Bundle.main.loadNibNamed("View1", owner: self, options: nil)?.first as? UIView,
let view2 = Bundle.main.loadNibNamed("View2", owner: self, options: nil)?.first as? UIView,
let view3 = Bundle.main.loadNibNamed("View3", owner: self, options: nil)?.first as? UIView else { return }
infiniteCarousel.slides = [view1, view2, view3]
}If You have
<Your App>[Storyboard] Unknown class LMInfiniteCarousel in Interface Builder file.error after run, add
LastManifoldInfiniteCarouselas module.
LastManifoldInfiniteCarousel gives user possibility to customize view.
You can set it in the interface builder, or you can set it programmatically. Slides are loaded proportionally to superview.
widthPercent //The width of the main slide proportional to superview(default: 70)
heightPercent //The height of the main slide proportional to superview(default: 70)
sideViewPercentSize //Proportional size of side slides to the main slide(default: 70)
slidesOffset //Distance between slides(default: 10)Example:
infiniteCarousel.widthPercent = 80Or in interface builder
You can add UIPageControl and take its value from number of pages from getSlidesCount() func.
pageControl.numberOfPages = infiniteCarousel.getSlidesCount()To update UIPageControl, use the pageChanged() func from delegate. Add
infiniteCarousel.delegate = selfand
extension ViewController: LMInfiniteCarouselDelegate {
func pageChanged() {
pageControl.currentPage = infiniteCarousel.getCurrentSlideIndex()
}
}

