struct ContentView_Previews : PreviewProvider {
static var previews: some View {
ContentView().environment(\.colorScheme, .dark)
}
}
I am using the above code to achieve dark mode on my demo project but its not working.
Any help or insight would be really appreciated.
This seems to be a bug in Xcode 11.0 beta. A temporary workaround is to wrap your content inside a NavigationView
.
For example, the following code will not take effect in dark mode preview:
var body: some View {
Text("Hello World")
}
But after wrapping the content in a NavigationView
, dark mode preview works as expected:
var body: some View {
NavigationView {
Text("Hello World")
}
}
Result:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With