Here's a sample implementation of containerBackground. LMEntryView is your widget view.
struct LMWidget: Widget {
var supportedFamilies: [WidgetFamily] {
[.systemSmall,
.systemMedium]
}
var body: some WidgetConfiguration {
StaticConfiguration(kind: "LMWidget",
provider: LMTimelineProvider()) { entry in
if #available(iOS 17, *) {
LMEntryView(entry: entry)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.containerBackground(Color("WidgetBackground"), for: .widget)
} else {
LMEntryView(entry: entry)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color("WidgetBackground"))
}
}
.configurationDisplayName("L_M_Widget_Title".localized)
.description("L_M_Widget_Description".localized)
.supportedFamilies(supportedFamilies)
.contentMarginsDisabled()
}
}
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags: