Shape
The Shape type defines a visual clipping or background shape used in view modifiers such as clipShape, background, or border. It mirrors SwiftUI's Shape protocol and supports standard system shapes and custom rounded rectangle configurations.
Overview
A Shape can be:
- A named shape keyword (
'circle','rect', etc.) - A custom shape object that defines corner radius or per-corner rounding.
These shapes are aligned within the frame of the containing view and are commonly used for clipping, masking, or background styling.
Built-in Shapes
'rect'
A standard rectangle. Can be customized with corner radius via the object form.
'circle'
A perfect circle centered within the view’s frame. Its radius is half the length of the frame's shortest side.
'capsule'
An elongated oval shape that spans the full width or height of the frame. Equivalent to a rounded rectangle with a corner radius equal to half of the shorter side.
'ellipse'
An ellipse that fills the frame.
'buttonBorder'
A system-resolved shape for button borders. It automatically adapts based on platform and system context.
'containerRelative'
A container-adaptive shape. If a container shape is defined in the view hierarchy, this resolves to a version of that shape. Otherwise, it defaults to a rectangle.
Custom Rectangle Shapes
To customize corner appearance on a rectangle, use one of the following object forms:
Rounded Rectangle with Uniform Corner Radius
cornerRadius: Radius applied uniformly to all corners.style(optional): Corner style, such as'circular'or'continuous'.
Example
Rounded Rectangle with Corner Size
- Allows specifying an elliptical radius with different width and height.
Example
Rounded Rectangle with Per-Corner Radii
- Gives precise control over the rounding of each corner individually.
Example
RoundedCornerStyle
Optional style that affects the curvature:
"circular": Traditional iOS-style round corners."continuous"(default): Smooth and adaptive curves, typically used in modern UI designs.
