SwiftUI 如何在 Light 主题(外观)上更改 TextField 的背景颜色?

SwiftUI how to change background color for TextField on Light theme (appearance)?

问题是 .background() 修改器在不同主题上的工作。

绝对相同的代码对两个主题有不同的效果:

我这边有问题还是这是 swiftUI 的错误?

        TextField("Any text", text: $anyText)
            .background(Color.red)

深色模式的人机界面指南部分内容如下:

Use the system-provided label colors for labels. The primary, secondary, tertiary, and quaternary label colors adapt automatically to light and dark appearances. For related guidance, see Typography.

https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/dark-mode/

尝试为您的文本设置 .secondary() 颜色

如果使用 "Mac Catalyst project" 而不是任何其他类型的项目,问题将得到解决。

没有这种行为,它在两个主题上都完美运行: