我知道我可以使用以下代码在SwiftUI中更改 View 背景颜色:
.background(Color(.systemGroupedBackground))
但是我无法为小部件背景颜色本身做这件事!我使用以下代码:
struct XWidget: Widget { // MARK: Widget is defined here
var body: some WidgetConfiguration {
StaticConfiguration(
kind: "xWidget",
provider: xProvider(),
placeholder: Text("Loading...")) { entry in
xWidgetEntryView(entry: entry).background(Color(.systemGroupedBackground)) // <= here
}.supportedFamilies([.systemSmall, .systemMedium, .systemLarge])
}
}
但是结果是这样的:最佳答案
StaticConfiguration(
kind: "xWidget",
provider: xProvider(),
placeholder: Text("Loading...")) { entry in
xWidgetEntryView(entry: entry)
.frame(maxWidth: .infinity, maxHeight: .infinity) // << here !!
.background(Color.green)
}.supportedFamilies([.systemSmall, .systemMedium, .systemLarge])
关于ios - 无法更改iOS14小部件的背景颜色,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/63028813/