Is it possible to force the use of the dark or light material in SwiftUI regardless of the current color scheme? Using .preferredColorScheme
will apply the color scheme to the entire view and not only the material. The reason is that I'm using an AVPlayer
and I need to overlay additional UI that should match the appearance of the player's UI, which seems to always use dark material.
The only work-around I am aware of, is implementing an UIBlurEffect
through an UIViewRepresentable
, e.g. with this package: https://github.com/twostraws/VisualEffects
CodePudding user response:
Use this as your background modifier:
.background {
Color.clear
.background(.ultraThinMaterial)
.environment(\.colorScheme, .dark)
}