TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Sep 2016 |
SPMSupports SPM | ✗ |
Maintained by Alex Corlatti.
To run the example project, clone the repo, and run pod install
from the Example directory first.
ACPaginatorViewController is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "ACPaginatorViewController"
Your viewController must conform the ACPaginatorViewControllerDelegate
so it must to implements these three variables:
@IBOutlet weak var pageControl: UIPageControl?
@IBOutlet weak var containerView: UIView!
lazy var orderedViewControllers: [UIViewController] = {
guard let
firstVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("First") as UIViewController?,
secondVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("Second") as UIViewController?,
thirdVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("Third") as UIViewController? else { return [] }
return [firstVC, secondVC]
}()
In your storyboard connect a UIContainerView
to your variable containerView
and the embedded UIPageViewController
must to be a ACPaginatorViewController
, optionally you can connect a UIPageControl
to your pageControl
variable.
Return to your viewController file and in the prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
method you have to pass to the navigator the ordered array of views and tell it that the view conforms to its protocol. You can also specify from which index start to show the views.
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let paginatorViewController = segue.destinationViewController as? ACPaginatorViewController {
paginatorViewController.orderedViewControllers = orderedViewControllers
paginatorViewController.paginationDelegate = self
paginatorViewController.currentViewControllerIndex = 0 // By default is 0, so you can set it only if you need to start from a different index
}
}
Optionally you can implement these two methods to do something when the number of views change or when a page is turned.
func paginatorViewController(paginatorViewController: ACPaginatorViewController, didUpdatePageCount count: Int) {
// Do something
}
func paginatorViewController(paginatorViewController: ACPaginatorViewController, didUpdatePageIndex index: Int) {
// Do something
}
Alex Corlatti, [email protected]
ACPaginatorViewController is available under the MIT license. See the LICENSE file for more info.