A simple iOS framework that allows developers to create onboarding experiences.
SwiftyOnboard makes it easy to add onboarding to any iOS application. SwiftyOnboard handles all of the logic behind the pagination of views, which allows you to quickly add a highly customizable onboarding to your app, all in a lightweight framework.
- iOS 9.0+
- Xcode 7.3+
You can use CocoaPods to install SwiftyOnboard
by adding it to your Podfile
:
use_frameworks!
pod 'SwiftyOnboard'
If you get the Unable to find a specification for `SwiftyOnboard`.
error after running pod install
.
Run the following commands on your project directory:
pod repo update
pod install
- Drag and drop
SwiftyOnboard.swift
SwiftyOnboardOverlay.swift
SwiftyOnboardPage.swift
in your project. - That's it!
- Import
SwiftyOnboard
module to yourViewController
class
import SwiftyOnboard
- Add
SwiftyOnboard
toViewController
, then set dataSource and delegate for it
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let swiftyOnboard = SwiftyOnboard(frame: view.frame)
view.addSubview(swiftyOnboard)
swiftyOnboard.dataSource = self
swiftyOnboard.delegate = self
}
}
- Conform your
ViewController
toSwiftyOnboardDataSource
protocol and implement all the methods, e.g.
extension ViewController: SwiftyOnboardDataSource {
func swiftyOnboardNumberOfPages(swiftyOnboard: SwiftyOnboard) -> Int {
return 3
}
func swiftyOnboardPageForIndex(swiftyOnboard: SwiftyOnboard, index: Int) -> SwiftyOnboardPage? {
let page = SwiftyOnboardPage()
return page
}
func swiftyOnboardViewForOverlay(swiftyOnboard: SwiftyOnboard) -> SwiftyOnboardOverlay? {
let overlay = SwiftyOnboardOverlay()
return overlay
}
}
SwiftyOnboard
works with default implementation. Override it to customize its behavior
SwiftyOnboard has the following properties:
public var dataSource: SwiftyOnboardDataSource?
An object that supports the SwiftyOnboardDataSource protocol and can provide views to populate the SwiftyOnboard.
public var delegate: SwiftyOnboardDelegate?
An object that supports the SwiftyOnboardDelegate protocol and can respond to SwiftyOnboard events.
public var shouldSwipe: Bool
Whether or not swiping is enabled [default = true].
SwiftyOnboard class has the following methods:
func goToPage(index: Int, animated: Bool)
This method allows you to move to a certain page in the onboarding.
The SwiftyOnboard follows the Apple convention for data-driven views by providing two protocol interfaces, SwiftyOnboardDataSource and SwiftyOnboardDelegate.
SwiftyOnboardDataSource protocol has the following methods:
func swiftyOnboardNumberOfPages(swiftyOnboard: SwiftyOnboard) -> Int
Return the number of items (pages) in the onboarding.
func swiftyOnboardViewForBackground(swiftyOnboard: SwiftyOnboard) -> UIView?
Return a view to be displayed as the background of the onboarding.
func swiftyOnboardPageForIndex(swiftyOnboard: SwiftyOnboard, index: Int) -> SwiftyOnboardPage?
Return a view (page) to be displayed at the specified index in the onboarding.
func swiftyOnboardViewForOverlay(swiftyOnboard: SwiftyOnboard) -> SwiftyOnboardOverlay?
Return an overlay (view) to be displayed on top of the onboarding pages. e.g. [The continue and skip buttons which don't move with the pages, also included is the page control]
func swiftyOnboardOverlayForPosition(swiftyOnboard: SwiftyOnboard, overlay: SwiftyOnboardOverlay, for position: Double)
Edit the overlay (view) for the desired position. e.g. [Change the "continue button" text to "Done", when the last page is reached]
SwiftyOnboardDelegate protocol has the following methods:
func swiftyOnboard(swiftyOnboard: SwiftyOnboard, currentPage index: Int)
This method is called whenever a page is shown, it holds the index to that page. It is called regardless of whether the page was swiped programmatically or through user interaction.
func swiftyOnboard(swiftyOnboard: SwiftyOnboard, leftEdge position: Double)
This method is called whenever the pages are scrolling, it holds the current distance between the left side of the screen and the left side of the first page.
- Carthage is not supported
- Landscape mode is not supported
I want to see your amazing onboarding. Take screenshots and/or record a gif and send it my way!
Distributed under the MIT license. See LICENSE
for more information.