When you want to specify how transparency works when views are layered on top of one another, you can use a modifier called .blendMode
. There are 21 different modes in the BlendMode
enum, so I’m adding them all to a static allCases
property to add conformance to the CaseIterable
protocol.
This will allow me to show the existing modes in a Picker
, allowing me to choose which one to apply.
I’ve also added conformance to the Identifiable protocol, which means I won’t have to add id: \.self
to my ForEach
.
As you can see there is also a demo area that shows two views layered on top of each other using the blend mode you select.
Many of them don’t show the text, but I noticed that exclusion does.
You can also try mixing and matching blend modes, or changing the views in your demo area to see the effect.