SwiftUI: preferredColorScheme doesn't change status bar style

Viewed 314

For example, if the device is in dark mode and I set the color scheme to light with the code below, the status bar is invisible because it's still white and won't get updated until I do something like bring up the keyboard or trigger an action sheet.

struct ContentView: View {
    var body: some View {
        Text("Hello, world!")
        .preferredColorScheme(.light)
    }
}

This somehow works on my iPad but not on my iPhone or any of the simulators. And I couldn't find a way to change the status bar style with the SwiftUI App life cycle.

Am I missing something here? Does anyone have a solution for this?

Screenshot of status bar not visible

1 Answers

Try using environment modifier instead

.environment(\.colorScheme, .light)
Related