问题
I'm am trying to achieve dark mode within my iOS application using SwiftUI: simple test would be to change the background colour.
I have set up my colour set as seen below:
ContentView.swift:
import SwiftUI
struct ContentView : View {
@EnvironmentObject var session: SessionStore
func getUser () {
session.listen()
}
var body: some View {
Group {
if (session.session != nil) {
VStack {
WelcomeView()
.background(Color("bg"))
.edgesIgnoringSafeArea(.all)
}
} else {
VStack {
SigninView().transition(.move(edge: .bottom))
}.frame(maxHeight: .infinity)
.background(Color("bg"))
.edgesIgnoringSafeArea(.all)
}
}.animation(.spring())
.onAppear(perform: getUser)
}
}
This doesn't work. However, when forcing dark mode with .colorScheme(.dark)
after .onAppear
- it works.
When debugging with @Environment (\.colorScheme) var colorScheme:ColorScheme
it returns light, even though my iPhone is set to Dark Mode.
Have I missed something?
回答1:
I figured it out. Turns out User Interface Style was set to light
in my Info.plist file - just delete it.
来源:https://stackoverflow.com/questions/59845579/swiftui-dark-mode-not-detected-when-testing-on-device