swift - 在 iOS 14 Widget 扩展中禁用灯光模式

标签 swift swiftui widget ios14 widgetkit

我的应用程序仅支持 DarkMode,并且我正在为 iOS 14 集成 Widget。

有什么方法可以禁用 Widget 的 LightMode 吗? (已在主应用.plist中添加UIUserInterfaceStyle,但不适用于Widget)

  • Stock 的 WidgetKit 即使在编辑模式下也始终显示 DarkMode。

Stock Widget always displaying DarkMode even in Editting Widget

我尝试使用@Environment(\.colorScheme) var colorScheme,但是当打开Widget的编辑模式时,浅色主题仍然可用。

最佳答案

将所需的颜色添加到 WidgetKit 的资源目录中,然后在 WidgetKit 的build设置中设置 NSWidgetBackgroundColorName。

文档: https://developer.apple.com/documentation/bundleresources/information_property_list/nswidgetbackgroundcolorname

关于swift - 在 iOS 14 Widget 扩展中禁用灯光模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65136879/

相关文章:

swiftui - 将 'badgeValue' 添加到 SwiftUI 中的选项卡项

ios - EKEventStore 与 iOS Widget 错误 : [EventKit] Client tried to open too many connections to calaccessd. 拒绝打开另一个

ios - 如何存储大量字符串

ios - AVAssetImageGenerator 使用动画工具和视频合成生成带有绿色像素的图像

内容匹配特定协议(protocol)的数组上的 Swift 运算符, "where"关键字用法

swift - 从 setUserTrackingMode(.Follow, animated : true)

json - 使用 ForEach 的多个 NavigationLink

swiftui - 是否可以使用 SwiftUI 在 TextField 上设置字符限制?

python - 如何禁用 Kivy 中的小部件?

java - 带有VAADIN 8,Gradle和Spring Boot的 Canvas 插件