Declaration
compose().shadow({
color?: SwiftUI.Color,
radius: number,
x?: number,
y?: number,
})nonisolated func shadow(
color: Color = Color(.sRGBLinear, white: 0, opacity: 0.33),
radius: CGFloat,
x: CGFloat = 0,
y: CGFloat = 0
) -> some ViewParameters
options.colorSwiftUI.ColorThe shadow's color.
options.radius*numberA measure of how much to blur the shadow. Larger values result in more blur.
options.xnumberAn amount to offset the shadow horizontally from the view.
options.ynumberAn amount to offset the shadow vertically from the view.
Return value
A view that adds a shadow to this view.
Discussion
Use this modifier to add a shadow of a specified color behind a view.
You can offset the shadow from its view independently in the horizontal
and vertical dimensions using the x and y parameters. You can also
blur the edges of the shadow using the radius parameter. Use a
radius of zero to create a sharp shadow. Larger radius values produce
softer shadows.
The example below creates a grid of boxes with varying offsets and blur. Each box displays its radius and offset values for reference.
struct Shadow: View {
let steps = [0, 5, 10]
var body: some View {
VStack(spacing: 50) {
ForEach(steps, id: \.self) { offset in
HStack(spacing: 50) {
ForEach(steps, id: \.self) { radius in
Color.blue
.shadow(
color: .primary,
radius: CGFloat(radius),
x: CGFloat(offset), y: CGFloat(offset))
.overlay {
VStack {
Text("\(radius)")
Text("(\(offset), \(offset))")
}
}
}
}
}
}
}
}The example above uses Color.primary as the color to make the
shadow easy to see for the purpose of illustration. In practice,
you might prefer something more subtle, like Color.gray-8j2b.
If you don't specify a color, the method uses a semi-transparent
black.
See also
More in Appearance.
- backgroundSets the view's background to a style.
- badgeGenerates a badge for the view from a localized string resource.
- badgeProminenceSpecifies the prominence of badges created by this view.
- borderAdds a border to this view with the specified style and width.
- buttonSizingThe preferred sizing behavior of buttons in the view hierarchy.
- containerBackgroundSets the container background of the enclosing container using a view.
- headerProminenceSets the header prominence for this view.
- hiddenHides this view unconditionally.
- imageScaleScales images within the view according to one of the relative sizes available including small, medium, and large images sizes.
- labelIconToTitleSpacingSet the spacing between the icon and title in labels.
- labelReservedIconWidthSet the width reserved for icons in labels.
- labelsHiddenHides the labels of any controls contained within this view.