Component

Dark Mode

Learn to add Dark Mode to your iOS App (Supports Xcode 16 and iOS 18)

Dark Mode

Just copy the below code and modify according to your needs.

import SwiftUI

struct DarkModeToggleView: View {
    @State private var isDarkMode = false // State to track the mode

    var body: some View {
        VStack {
            // Title Text
            Text("Dark Mode Toggle")
                .font(.largeTitle)
                .fontWeight(.bold)
                .padding()

            // Example image to showcase the mode effect
            Image(systemName: isDarkMode ? "moon.fill" : "sun.max.fill")
                .resizable()
                .scaledToFit()
                .frame(width: 100, height: 100)
                .foregroundColor(isDarkMode ? .yellow : .orange) // Custom color for each mode
                .padding()

            // Toggle switch with label
            Toggle(isOn: $isDarkMode) {
                Text(isDarkMode ? "Dark Mode" : "Light Mode")
                    .font(.headline)
            }
            .toggleStyle(SwitchToggleStyle(tint: .blue)) // Beautiful blue accent color
            .padding()

        }
        // Apply the color scheme dynamically
        .preferredColorScheme(isDarkMode ? .dark : .light)
        .animation(.easeInOut, value: isDarkMode) // Smooth transition between modes
        .frame(maxWidth: .infinity, maxHeight: .infinity)
        .background(isDarkMode ? Color.black : Color.white) // Set background color based on mode
        .edgesIgnoringSafeArea(.all)
    }
}

struct DarkModeToggleView_Previews: PreviewProvider {
    static var previews: some View {
        DarkModeToggleView()
    }
}

Time to build your iOS App?

ShipiOS provides you SwiftUI boilerplate, How-to Guides, Components Library and extra rewards!

Get ShipiOS Package
ShipiOS.App

I told you it's more than just a boilerplate :)

Made with ❤️ on 🌍

Need help? Reach out on:

© Copyright 2024 ShipiOS.App - All rights reserved.