I am currently developing an iOS widget with SwiftUI and have a strange behaviour of the background-image of my medium-sized widget.
I am setting a background-image depending on the current color mode of the device, which works most of the time. But when the app is in the background for a couple of minutes, the background-image goes black, which makes the text unreadable. Any other UI-elements are still visible. When I resume to my app, the widget refreshes itself and the background-image is visible again.
The background-images are included in my image.assets of my widget-extension, so it should be always accessible for the widget, shouldn’t it?
This widget is available for iOS 14 and above.
This is how I set the background-image:
struct MediumWidget: View {
@Environment(\.colorScheme) var colorScheme
var body: some View {
HStack(alignment: .center, spacing: nil) {
// Content (shortend)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.edgesIgnoringSafeArea(.all)
.background(
backgroundImage
.renderingMode(.original)
.resizable()
.scaledToFill()
)
}
var backgroundImage: Image {
if colorScheme == .dark {
return Image("dark")
}
return Image("light")
}
}
I am clueless of what to do, does someone know what I am doing wrong?
Thank you in advance!
EDIT 1: This problem only occurs with these two background-images. When I use any other background-image, the widget does not go black.