How to make a splash screen in Swift UI

Super basic splash screen tutorial; here we go.

Step 1

Get some art. Put it in your assets folder. Here, borrow my logo.

Place it in your assets folder.

Make a new view and add the logo to the screen.

Make a Main View as well.

Step 2

Now to make the magic happen.

Make a @State variable. When this variable changes, we can run code. So we will change this when we want to change views.

Now let’s wrap all of our code in an if.

Now we want to say: When the ZStack appears, push some code on a background thread that will run after a delay. After the delay change isActive = trueThis will cause Swift UI to change the view!

We use DispatchQueue.main.asyncAfter so we can input a time when the code should run. i.e. run this code after now + 2.5 seconds.

And there we have it! After 2.5 seconds our second view appears!

Here is an example of the code. I hope it was useful. Thank you for reading.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Liyicky

Liyicky

Hey, I’m Jason Cheladyn. Going back to the coding world after 6 years of teaching English in Japan. https://www.twitter.com/liyicky https://www.liyicky.com