SwiftUI Make Onboarding View like Apple’s Apps

Clementlvx
Dev Genius
Published in
2 min readJul 2, 2020

--

Do you want to create an Onboarding View like Apple’s Apps ?

You’re in the right place !

Take your project where you want to incorporate this functionality, create new SwiftUI View file, we will name it “OnboardingView.swift”.

Incorporate this code in your OnboardingView :

In order to be able to go from OnBoardingView of the first startup to the other views for all startups that will follow, we create LaunchView that will check whether it is the first startup of the application or not.

Start by creating an ObservableObject class in which you initialize an if on the boolean value of LaunchBefore.

The LaunchBefore value are changed when you click on the next button in OnboardingView :

Button(action: {                
UserDefaults.standard.set(true, forKey: "LaunchBefore")
...

If the value of LaunchBefore isn’t true this means that it is the first launch then the value of currentPage will be onBoardingView.
On the other hand, if the value of LaunchBefore is true then the value of currentPage will be ContentView and this will mean that the application has already been launched.

Finally, it’s necessary to publish the currentPage variable so that it is accessible by LaunchView.

After coding the OnboardingView, you can change the root view in SceneDelegate so that the application launches LaunchView at startup :

And now, you can build and run the application and all are normally ok.

You can find the full project here.

Thanks to have read my first post.

--

--