Crashtor
Crashtor

Reputation: 1279

Shadow opacity swiftUI

I have an image with a border around it to which I would like to add a shadow with some offset. Although I think the default opacity of the shadow is too dark, what's the correct property for opacity?

var body: some View {

    Image("football")

        .resizable()
        .scaledToFit()
        .frame(width: 100.0, height: 100.0)
        .clipShape(Circle())
        .overlay(Circle()
        .stroke(Color.white, lineWidth: 4))
        .shadow(radius: 10.0, x: -10.0, y: -10.0)

}

Upvotes: 8

Views: 7930

Answers (2)

Imran0001
Imran0001

Reputation: 628

You can control the shadow by changing the value of X position and Y position.

Text("Hello")
      .frame(width: 100, height: 100)
      .background(Color.red)
      .shadow(color: Color.black.opacity(0.3), radius: 5, x: -15.5, y: 0.0)
      .shadow(color: Color.black.opacity(0.3), radius: 5, x: 15.0, y: 0.0)

Upvotes: 2

Alladinian
Alladinian

Reputation: 35616

You can pass a Color with reduced opacity to your shadow:

.shadow(color: Color.black.opacity(0.2), radius: 10.0, x: -10.0, y: -10.0)

Note: The default shadow color is a black with 0.33 opacity

Color(.sRGBLinear, white: 0, opacity: 0.33)

Upvotes: 26

Related Questions