PaginatedScrollView
Simple paginated UIScrollView subclass that supports UIViewControllers as pages. It handles rotation pretty well, too.
Usage
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]
}
}
PaginatedScrollViewDelegate
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, willMoveFromIndex index: Int)
}
Installation
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"
License
PaginatedScrollView is available under the MIT license. See the LICENSE file for more info.
Author
Elvis Nuñez, @3lvis