Is there any way to have the
.background(.ultraThinMaterial)
in SwiftUI without it having a background color? It seems that it has some light white dim as a background because if it would just blur the background alone, it shouldn't show any color, only if content is scrolled behind.
Desired outcome:
Here are two possible workarounds.
1. Show the Material conditionally
In your question you said:
So as suggested in a comment, you could make the material background conditional on content actually being scrolled up behind it. If you apply changes
withAnimation
then it works quite well:2. Use a darker background to compensate for the material effect
The lighter shade of background that is caused by the material effect can be almost eliminated, or at least significantly reduced, if you make the background for the content behind the material even darker. In other words, you can compensate for the lighter shading by setting a darker background, just in that region.
Making the background darker is for the case of when dark mode is in operation. In light mode it works the other way and the content behind the material needs to be made lighter.
Testing on a simulator, I found that these combinations work quite well:
In dark mode, a main background of
Color(white: 0.15)
withColor.black
behind the material.In light mode, a main background of
Color(white: 0.91)
withColor.white
behind the material.Like this: