So, I am supporting three themes in my app, each with different tintColors. I\'m using @EnvironmetObject to track changes. However, I can\'t use it on SceneDelegate.swift fi
You can achieve it by calling
UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = .red
in willConnectTo
method of SceneDelegate
Update: posted this demo on GitHub - DemoWindowTint
The below demo is created on setting window's tintColor
(which is inherited by all subviews) using the approach provided in How to access own window within SwiftUI view?.
In demo I used NavigationView
with couple of NavigationLinks
and Button
showing Alert
.
Tested with following
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
let contentView = ContentView()
.environment(\.hostingWindow, { [weak window] in
return window })
window.rootViewController = UIHostingController(rootView: contentView)
self.window = window
...
struct ContentView: View {
@Environment(\.hostingWindow) var hostingWindow
... // body can be any
.onAppear {
// can be loaded from UserDefaults here, and later changed on any action
self.hostingWindow()?.tintColor = UIColor.red
}