8

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) } 

2 Answers 2

26

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)

Sign up to request clarification or add additional context in comments.

Comments

2

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) 

1 Comment

Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.