mamaral / Onboard

An iOS framework to easily create a beautiful and engaging onboarding experience with only a few lines of code.
MIT License
6.46k stars 764 forks source link

Swift example!! #133

Open Dershowitz011 opened 8 years ago

Dershowitz011 commented 8 years ago

Could you please give an example in swift please? :(

rcobelli commented 8 years ago
// Initialize onboarding view controller
var onboardingVC = OnboardingViewController()

// Create slides
let firstPage = OnboardingContentViewController.contentWithTitle("Welcome To The App!", body: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent ut.", image: UIImage(named: "image1"), buttonText: nil, action: nil)

let secondPage = OnboardingContentViewController.contentWithTitle("Step 1", body: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent ut.", image: UIImage(named: "image2"), buttonText: nil, action: nil)

let thirdPage = OnboardingContentViewController.contentWithTitle("Step 2:", body: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent ut.", image: UIImage(named: "image3"), buttonText: nil, action: nil)

let fourthPage = OnboardingContentViewController.contentWithTitle("Step 3", body: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent ut.", image: UIImage(named: "image4"), buttonText: nil, action: nil)

// Define onboarding view controller properties
onboardingVC = OnboardingViewController.onboardWithBackgroundImage(UIImage(named: "background.jpg"), contents: [firstPage, secondPage, thirdPage, fourthPage])
onboardingVC.shouldFadeTransitions = true
onboardingVC.shouldMaskBackground = false
onboardingVC.shouldBlurBackground = false
onboardingVC.fadePageControlOnLastPage = true
onboardingVC.pageControl.pageIndicatorTintColor = UIColor.darkGrayColor()
onboardingVC.pageControl.currentPageIndicatorTintColor = UIColor.whiteColor()
onboardingVC.skipButton.setTitleColor(UIColor.blackColor(), forState: .Normal)
onboardingVC.allowSkipping = false
onboardingVC.fadeSkipButtonOnLastPage = true

// Present presentation
self.presentViewController(onboardingVC, animated: true, completion: nil)

Someone let me know if I should add this as a pull request

ahadsheriff commented 8 years ago

@rcobelli Quick question...what did you have to import and did you just put all this inside viewDidLoad in your ViewController?

rcobelli commented 8 years ago

I added #import "OnboardingViewController.h" to my bridging header. Within my ViewController, I didn't have to import anything.

All this code is within a function that I call from viewDidAppear (where I check NSUserDefaults)

markdrayton247 commented 8 years ago

might have to add $(PROJECT_DIR)/Pods to your User Header Search Paths

nazrdogan commented 7 years ago

I made an example .maybe its help link

ninevcat commented 7 years ago

@nazrdogan still want a swift demo .i just want a project.thx

nazrdogan commented 7 years ago

@themachine15 I made quick example link

omarshamali commented 6 years ago

Swift 4

var onboardingVC = OnboardingViewController()

        let firstPage = OnboardingContentViewController(title: "Page Title", body: "Page body goes here.", image: UIImage(named: "steam.png"), buttonText: "Textff For Button") { () -> Void in
            // do something here when users press the button, like ask for location services permissions, register for push notifications, connect to social media, or finish the onboarding process
        }

        let secondPage = OnboardingContentViewController(title: "Page Title", body: "Pafqege body goes here.", image: UIImage(named: "palestine.png"), buttonText: "Tzext For Button") { () -> Void in
            // do something here when users press the button, like ask for location services permissions, register for push notifications, connect to social media, or finish the onboarding process
        }

        onboardingVC = OnboardingViewController(backgroundImage: UIImage(named: "steam.png"), contents: [firstPage, secondPage])

        onboardingVC.shouldBlurBackground = true

        self.present(onboardingVC, animated: true, completion: nil)