Auto slide PageViewController written in Swift
DLAutoSlidePageViewController
Auto slide PageViewController written in Swift.
Demo
Example
To run the example project, clone the repo, and run pod install
from the Example directory first.
Requirements
DLAutoSlidePageViewController requires iOS 10.0 and Swift 4.0 or above.
Installation
CocoaPods
PageViewController is available through CocoaPods. To install
it, simply add the following line to your Podfile:
pod "DLAutoSlidePageViewController"
Swift Package Manager
To integrate using Swift Package Manager, add the following as a dependency to your Package.swift:
.package(url: "https://github.com/DeluxeAlonso/DLAutoSlidePageViewController.git", .upToNextMajor(from: "1.2.0"))
Usage
Create an instance of DLAutoSlidePageViewController
and provide it with an array of UIViewController
's.
let firstVC = storyboard?.instantiateViewController(withIdentifier: 'FirstVC')
let secondVC = storyboard?.instantiateViewController(withIdentifier: 'SecondVC')
let pages = [firstVC, secondVC]
let pageViewController = DLAutoSlidePageViewController(pages: pages)
addChildViewController(pageViewController)
containerView.addSubview(pageViewController.view)
pageViewController.view.frame = containerView.bounds
Appearance and presentation configuration
There are two ways to configure the appearance and presentation of DLAutoSlidePageViewController
:
- You can do it globally using the
DefaultAutoSlideConfiguration
class before instantiation.
let pages = [firstVC, secondVC]
DefaultAutoSlideConfiguration.shared.timeInterval = 5.0
DefaultAutoSlideConfiguration.shared.interPageSpacing = 3.0
DefaultAutoSlideConfiguration.shared.hidePageControl = false
let pageViewController = DLAutoSlidePageViewController(pages: pages)
- You can create your own configuration instance that conforms to
AutoSlideConfiguration
protocol and pass it onDLAutoSlidePageViewController
's initializer.
struct CustomConfiguration: AutoSlideConfiguration {
var timeInterval: TimeInterval = 10.0
var navigationOrientation: UIPageViewController.NavigationOrientation = .vertical
}
let pages = [firstVC, secondVC]
let pageViewController = DLAutoSlidePageViewController(pages: pages, configuration: CustomConfiguration())
Available configuration properties
DLAutoSlidePageViewController
can be customized via the following properties:
Property | Type | Description |
---|---|---|
timeInterval | TimeInterval | Time interval to be used for each page automatic transition. |
transitionStyle | UIPageViewController.TransitionStyle | Styles for the page-turn transition. |
navigationOrientation | UIPageViewController.NavigationOrientation | Orientations for page-turn transitions. |
interPageSpacing | Float | Space between pages. |
spineLocation | UIPageViewController.SpineLocation | Locations for the spine. Only valid if the transition style is UIPageViewController.TransitionStyle.pageCurl. |
hidePageControl | Bool | Decides if page control is going to be shown or not. |
currentPageIndicatorTintColor | UIColor | The tint color to be used for the current page indicator. |
pageIndicatorTintColor | UIColor | The tint color to be used for the page indicator. |
pageControlBackgroundColor | UIColor | The background color to be used for the page control. |
Author
Alonso Alvarez, alonso.alvarez.dev@gmail.com
GitHub
https://github.com/DeluxeAlonso/DLAutoSlidePageViewController