Generic Instance Method

clipShape(_:style:)

Sets a clipping shape for the view.

Declaration

func clipShape<S>(_ shape: S, style: FillStyle = FillStyle()) -> some View where S : Shape

Parameters

shape

The clipping shape to use for this view. The shape fills the view’s frame, while maintaining its aspect ratio.

style

The fill style to use when rasterizing shape.

Return Value

A view that clips this view to shape, using style to define the shape’s rasterization.

Discussion

By applying a clipping shape to a view, you preserve the parts of the view covered by the shape, while eliminating other parts of the view. The clipping shape itself isn’t visible.

For example, this code applies clipping shape to a square image:

Image("artichokes")
    .clipShape(Circle())

The resulting view shows only the portion of the image that lies within the bounds of the circle.

See Also

Masking and Clipping Views

func clipped(antialiased: Bool) -> View

Clips the view to its bounding rectangular frame.

func cornerRadius(CGFloat, antialiased: Bool) -> View

Clips the view to its bounding frame, with the specified corner radius.

func mask<Mask>(Mask) -> View

Masks this view using the alpha channel of the given view.