View ModifieriOS 15.0+macOS 12.0+tvOS 15.0+watchOS 8.0+
Overloads
2 ways to call compose().containerShape(). Each is one SwiftUI overload, picked by the arguments you pass.
compose().containerShape(shape: SwiftUI.InsettableShape)nonisolated func containerShape<T>(
_ shape: T
) -> some View
where T : InsettableShapeParameters
shape*SwiftUI.InsettableShape
Discussion
The example below defines a view that shows its content with a rounded
rectangle background and the same container shape. Any
ContainerRelativeShape within the content matches the rounded
rectangle shape from this container inset as appropriate.
struct PlatterContainer<Content: View> : View {
@ContentBuilder var content: Content
var body: some View {
content
.padding()
.containerShape(shape)
.background(shape.fill(.background))
}
var shape: RoundedRectangle { RoundedRectangle(cornerRadius: 20) }
}- SeeAlso:
View.containerShape(_:)-(RoundedRectangularShape)
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.
- clipShapeSets a clipping shape for 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.