TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Feb 2017 |
SwiftSwift Version | 3.0 |
SPMSupports SPM | ✓ |
Maintained by Elvis Nuñez.
Simple paginated UIScrollView subclass that supports UIViewControllers as pages. It handles rotation pretty well, too.
import UIKit
class RootController: UIViewController {
var pages: [UIViewController] {
let firstController = UIViewController()
firstController.view.backgroundColor = UIColor.redColor()
let secondController = UIViewController()
secondController.view.backgroundColor = UIColor.greenColor()
let thirdController = UIViewController()
thirdController.view.backgroundColor = UIColor.purpleColor()
return [firstController, secondController, thirdController]
}
lazy var scrollView: PaginatedScrollView = {
let view = PaginatedScrollView(frame: view.frame, parentController: self, initialPage: 0)
view.viewDataSource = self
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(scrollView)
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
scrollView.configure()
}
}
extension RootController: PaginatedScrollViewDataSource {
func numberOfPagesInPaginatedScrollView(paginatedScrollView: PaginatedScrollView) -> Int {
return pages.count
}
func paginatedScrollView(paginatedScrollView: PaginatedScrollView, controllerAtIndex index: Int) -> UIViewController {
return pages[index]
}
}
UIPageViewController
is kind of lame when it comes to knowing exactly when you have switched to the next page or went back to the previous one. That’s the main reason why PaginatedScrollView
exists.
protocol PaginatedScrollViewDelegate: class {
func paginatedScrollView(paginatedScrollView: PaginatedScrollView, didMoveToIndex index: Int)
func paginatedScrollView(paginatedScrollView: PaginatedScrollView, didMoveFromIndex index: Int)
}
PaginatedScrollView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'PaginatedScrollView'
PaginatedScrollView is also available through Carthage. To install it, simply add the following line to your Cartfile:
github "3lvis/PaginatedScrollView"
PaginatedScrollView is available under the MIT license. See the LICENSE file for more info.
Elvis Nuñez, @3lvis