Created
August 29, 2018 15:04
-
-
Save shawnbierman/f5550e16d0227c6fd198973bf9d01fac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// OnboardingController.swift | |
// Onboarding | |
import UIKit | |
class OnboardingController: UICollectionViewController, UICollectionViewDelegateFlowLayout { | |
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { | |
super.viewWillTransition(to: size, with: coordinator) | |
guard let flowLayout = collectionView?.collectionViewLayout as? UICollectionViewFlowLayout else { | |
return | |
} | |
flowLayout.invalidateLayout() | |
} | |
let onboardingPages = [ | |
Onboarding(headerLabelText: "Welcome", footerForwardButtonText: "Begin", footerBackButtonText: nil), | |
Onboarding(headerLabelText: "Server Configuration", footerForwardButtonText: "Connect", footerBackButtonText: nil), | |
Onboarding(headerLabelText: "Choose Facility", footerForwardButtonText: "Next", footerBackButtonText: "Back"), | |
Onboarding(headerLabelText: "Choose Unit", footerForwardButtonText: "Next", footerBackButtonText: "Back"), | |
Onboarding(headerLabelText: "Choose Room", footerForwardButtonText: "Save and launch", footerBackButtonText: "Back") | |
] | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
collectionView?.backgroundColor = .white | |
collectionView?.register(OnboardingCell.self, forCellWithReuseIdentifier: OnboardingCell.cellId) | |
collectionView?.isPagingEnabled = true | |
collectionView?.isScrollEnabled = true | |
collectionView?.showsHorizontalScrollIndicator = false | |
collectionView?.showsVerticalScrollIndicator = false | |
} | |
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { | |
return onboardingPages.count | |
} | |
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { | |
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: OnboardingCell.cellId, for: indexPath) as! OnboardingCell | |
let page = onboardingPages[indexPath.item] | |
cell.onboarding = page | |
return cell | |
} | |
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { | |
return CGSize(width: view.frame.width, height: view.frame.height) | |
} | |
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat { | |
return 0 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment