containerShape

Sets the container shape to use for any container relative shape within this view.

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.

React
compose().containerShape(shape: SwiftUI.InsettableShape)
Swift
nonisolated func containerShape<T>(
    _ shape: T
) -> some View
where T : InsettableShape

Parameters

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.