Super Simple Pager
To run the example project, clone the repo, and run pod install
from the SSPagerExample directory first.
SSPager is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'SSPager', '~> 1.0.0'
Create a Package.swift
file.
import PackageDescription
let package = Package(
name: "SSPager",
dependencies: [
.package(url: "https://github.com/9oya/SSPager.git", from: "1.0.0")
],
targets: [
.target(
name: "SSPager",
path: "SSPager"
)
]
)
@IBOutlet weak var pagerView: SSPagerView!
pagerView.dataSource = self
pagerView.delegate = self
pagerView.register(SSPagerViewCell.self, forCellWithReuseIdentifier: "SSPagerViewCell"))
func numberOfPages(_ pagerView: SSPagerView) -> Int
func pagerView(_ pagerView: SSPagerView, cellForItemAt index: Int) -> SSPagerViewCell
pagerView.interitemSpacing = 20.0
pagerView.isInfinite = true
pagerView.automaticSlidingInterval = 2.0
pagerView.pagingMode = .oneStep // .scrollable .disable
pagerView.itemSize = CGSize(width: cellWidth, // view.frame.width * 0.7
height: cellHeight) // view.frame.height * 0.7
pagerView.contentsInset = UIEdgeInsets(top: 100,
left: (view.bounds.width - cellWidth) / 2,
bottom: 100,
right: (view.bounds.width - cellWidth) / 2)
func scrollToPage(at index: Int, animated: Bool)
func pagerViewDidSelectPage(at index: Int)
func pagerViewWillEndDragging(_ scrollView: UIScrollView, targetIndex: Int)
SSPager provide a subspec SSPager/Rx
pod 'SSPager/Rx', '~> 1.0.0'
@IBOutlet weak var pagerView: SSPagerView!
/*
You don't need to set delegate and datasource
`pagerView.dataSource = self`
`pagerView.delegate = self`
*/
pagerView.register(SSPagerViewCell.self, forCellWithReuseIdentifier: "SSPagerViewCell")
// let itemColors = [UIColor.red, UIColor.orange, UIColor.yellow, UIColor.green, UIColor.blue]
Observable.just(itemColors)
.bind(to: pagerView.rx.pages(cellIdentifier: defaultCellId))
{ idx, color, cell in
cell.backgroundColor = color
}
.disposed(by: disposeBag)
pagerView.rx.pageSelected
.bind(onNext: { idx in
print("Page \(idx) is selected.")
})
.disposed(by: disposeBag)
Eido Goya, eido9oya@gmail.com
SSPager is available under the MIT license. See the LICENSE file for more info.