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)
}
Any SwiftUI view can be partially or wholly transparent using the opacity() modifier. This accepts a value between 0 (completely invisible) and 1 (fully opaque), just like the alpha property of UIView in UIKit.
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)
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With