How to config launch screen in SwiftUI

Apr 22, 2024#swiftui

In iOS development, a launch screen (also known as a splash screen) is the initial screen that appears when your app is launched. It provides a seamless transition from launching the app to displaying its first screen.

The launch screen appears instantly when your app starts up and is quickly replaced with the app’s actual content. It gives users the impression that your app is fast and responsive by providing context while the app initializes.

Setting up launch screen in SwiftUI is no different from UIKit app.

Using Info.plist

If your project already has a launch screen configured via a Storyboard, you can remove it. Remove the “Launch screen interface file base name” (UILaunchStoryboardName) key from your project’s Info.plist.

Add a new key called “Launch Screen” (UILaunchScreen) of type dictionary, which supports several options:

  • Background color (UIColorName): Specify the name of a color to use as the background color on the launch screen. Provide a value for this key that’s the name of a color in Assets.
  • Image name (UIImageName): Provide the name of an image to display during app launch. The image will be centered on the launch screen. Use the same value as you set in Assets.
  • Image respects safe area insets (UIImageRespectsSafeAreaInsets): A Boolean that determines whether the launch image should respect the safe area insets.
  • Show navigation bar (UINavigationBar): A dictionary representing a navigation bar.
  • Show Tab bar (UITabBar): A dictionary representing a tab bar.
  • Show Toolbar (UIToolbar): A dictionary representing a toolbar.

Using Storyboard

Remove UILaunchScreen key in Info.plist if any. This tells Xcode you won’t be configuring the launch screen through the Info.plist.

Create a file LaunchScreen.storyboard and design it using elements like images, labels, and backgrounds.

Then you can set LaunchScreen.storyboard in target’s General tab under “App Icons and Launch Images” section.