Last active
February 16, 2024 09:42
-
-
Save babldev/d24bd1722c6ca3338a553db4078864cb to your computer and use it in GitHub Desktop.
Change background color of root view in SwiftUI, fixing white background during rotation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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