Skip to content

Instantly share code, notes, and snippets.

@babldev
Last active February 16, 2024 09:42
Change background color of root view in SwiftUI, fixing white background during rotation
//
// MyApp.swift
// MyApp
//
// Created by Brady Law on 8/25/23.
//
import SwiftUI
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.background(.black)
.onAppear {
if let window = (UIApplication.shared.connectedScenes.first as? UIWindowScene)?.windows.first {
window.rootViewController?.view.backgroundColor = .black
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment