Member-only story
Splash Screen in SwiftUI
1 min readOct 9, 2024
Following is the code for setup splash screen for 2.0 second in your app, you can customise the splash screen view as per your requirements. I am just showing image from asset to Splash screen.
import SwiftUI
struct SplashScreenView: View {
@State private var isActive = false
let splashDuration = 2.0 // Adjust the splash duration as needed
var body: some View {
ZStack {
// Full-screen background color
Color(UIColor(red: 0.87, green: 0.96, blue: 0.04, alpha: 1.00))
.ignoresSafeArea() // Extend the color to the entire screen
if isActive {
// Main content of your app, switch to ContentView after splash
ContentView()
} else {
// Splash image
Image("splashImage") // Make sure to have a splash image in assets
.resizable()
.scaledToFit()
.onAppear {
// Simulate a delay to show the splash screen
DispatchQueue.main.asyncAfter(deadline: .now() + splashDuration) {
withAnimation {
self.isActive = true
}
}
}
}
}
}
}
@main
struct yourApp: App {
var body: some Scene {
WindowGroup {
SplashScreenView()
}
}
}