Declaration
compose().clipShape(
shape: SwiftUI.Shape,
options?: {
style?: SwiftUI.FillStyle;
}
)nonisolated func clipShape<S>(
_ shape: S,
style: FillStyle = FillStyle()
) -> some View
where S : ShapeParameters
shape*SwiftUI.ShapeThe clipping shape to use for this view. The
shapefills the view's frame, while maintaining its aspect ratio.options.styleSwiftUI.FillStyleThe 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
Use clipShape(_:style:) to clip the view to the provided shape. 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 a circular clipping shape to a Text
view:
Text("Clipped text in a circle")
.frame(width: 175, height: 100)
.foregroundColor(Color.white)
.background(Color.black)
.clipShape(Circle())The resulting view shows only the portion of the text that lies within the bounds of the circle.
See also
More in Drawing and shapes.
- blendModeSets the blend mode for compositing this view with overlapping views.
- buttonBorderShapeSets the border shape for buttons in this view.
- containerShapeSets the container shape to use for any container relative shape within this view.
- contentShapeSets the content shape for this view.
- coordinateSpaceAssigns a name to the view's coordinate space, so other code can operate on dimensions like points and sizes relative to the named space.
- materialActiveAppearanceSets an explicit active appearance for materials in this view.
- textInputBorderShapeSets the border shape for text input controls in the view hierarchy.