Widgets and Content Margins
If you have an app with widgets, be sure to check how the widgets look after compiling with Xcode 15.
The new .widgetContentMargins
are a nice addition, but I found adopting them in a way that allows the widgets to continue working well under iOS 16 to be a significant undertaking.
The new .contentMarginsDisabled()
modifier on WidgetConfiguration
is supposed to do nothing on iOS 16, but it makes the widget extension crash on iOS 16. Here is a modifier you can use instead:
extension WidgetConfiguration {
func `contentMarginsDisabledOnNewOperatingSystem`() -> some WidgetConfiguration {
if #available(iOSApplicationExtension 17.0, *) {
return self.contentMarginsDisabled()
} else {
return self
}
}
}
Since .contentMarginsDisabled()
is applied at the WidgetConfiguration
level, .contentMarginsDisabled()
cannot apply to just one size of a widget.