我有 .light 和 .dark 主题。
在预览中(MyContainer_Previews),我可以通过以下方式进行更改:
在预览中(MyContainer_Previews),我可以通过以下方式进行更改:
ForEach([.light,.dark], id: \.self) { theme in
Group {
...
}
.environment(\.colorScheme, theme) //This line
}
...
我如何在应用程序中更改主题(例如按钮操作)。
我试图在SceneDelegate中进行更改:
let contentView = ContentView()
contentView.environment(\.colorScheme, .dark) //Not work