【发布时间】:2021-03-04 06:16:50
【问题描述】:
我在 MacOS 11.01 上使用 Swift 5.3,并为 iOS 14.2 创建了一个新的“多平台”应用程序。我为亮/暗模式创建了自定义颜色资源,但无法让亮模式背景颜色显示在我的 TabView 上。 TabView 暗模式背景颜色看起来很好。
浅色模式背景颜色在 Xcode Preview 中看起来很完美,但是当我在 Sim 或我的设备上运行应用程序时,标签栏背景颜色在浅色模式下是清晰的,但在深色模式下显示正确的颜色。
I use the same color assets for coloring my NavigationView and both the light and dark mode colors appear correctly when the corresponding modes are selected.
最新的 SwiftUI 5.3 和颜色资产有什么明显的地方遗漏了吗?
我在 TabView 的 .onAppear 中使用以下代码
UITabBar.appearance().barTintColor = UIColor(named: "barBackground")
请注意,“barBackground”是我创建的自定义颜色集,用于向 NavigationView 和 TabView 添加浅色/深色模式背景颜色。
如果不清楚,很乐意提供更多信息。谢谢!
【问题讨论】:
标签: swiftui swiftui-navigationview swiftui-tabview