Great Filip Němeček article here on adapting a hot fix for this so it still works on iOS16 devices.
TLDR:
Add an extension with the OS check:
extension View {
func widgetBackground(_ backgroundView: some View) -> some View {
if #available(iOSApplicationExtension 17.0, *) {
return containerBackground(for: .widget) {
backgroundView
}
} else {
return background(backgroundView)
}
}
}
Add widgetBackground
to all of your different widgets (pick your background view/color, of course):
var body: some View {
VStack {
// widget content
}
.widgetBackground(Color.black)
}
Also, he mentions an interesting note about iOS17 widgets, where they force additional margin padding on your design.
You can disable this while generating WidgetConfiguration:
var body: some WidgetConfiguration {
//IntentConfiguration stuff
.contentMarginsDisabled()
}