I know I can change the views background colors in SwiftUI with this code:
.background(Color(.systemGroupedBackground))
But I can't do it for widget background color itself!
I use this code:
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])
}
}
But the result is like this:
You need to specify full frame, as on below demo
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])