Sebastian Boldt
Sebastian Boldt

Reputation: 5321

How to draw just a round shadow without the actual view

I'm a little stuck at the moment. I would like to draw a round shadow without giving the corresponding view an actual color. My idea was the following:

Circle()
.fill(Color.clear)
.shadow(color: .red, radius: 10)

Unfortunately, the system only seems to draw shadows for views that also have a color and relates to the opacity value of that view.

Does anyone know a way around this. I would be grateful for any tip.

Upvotes: 2

Views: 430

Answers (1)

Asperi
Asperi

Reputation: 257563

Shadow works only for opaque areas, so to mimic opacity we can use default system background color, like

Circle()
    .fill(Color(uiColor: .systemBackground))   // << here !!
    .shadow(color: .red, radius: 10)

and then you can place any content in overlay so it would look like over background with transparent shadowed circle.

See also https://stackoverflow.com/a/60740418/12299030.

Upvotes: 1

Related Questions