gpt4 book ai didi

ios - SwiftUI:在设备上测试时未检测到深色模式

转载 作者:行者123 更新时间:2023-11-29 05:09:09 26 4
gpt4 key购买 nike

我正在尝试使用 SwiftUI 在我的 iOS 应用程序中实现深色模式:简单的测试是更改背景颜色。

我已经设置了颜色集,如下所示: Colour Set in Assets

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)
}

}

这行不通。但是,当在 .onAppear 之后使用 .colorScheme(.dark) 强制使用深色模式时 - 它可以工作。

使用 @Environment (\.colorScheme) var colorScheme:ColorScheme 进行调试时,即使我的 iPhone 设置为深色模式,它也会返回 light

我错过了什么吗?

最佳答案

我明白了。结果我的 Info.plist 文件中的用户界面样式被设置为light - 只需将其删除即可。

User Interface Style

关于ios - SwiftUI:在设备上测试时未检测到深色模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59845579/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com