Instance Method インスタンスメソッド

containerShape(_:)

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

Declaration 宣言

func containerShape<T>(_ shape: T) -> some View where T : 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 {
    @ViewBuilder var content: Content
    var body: some View {
        content
            .padding()
            .containerShape(shape)
            .background(shape.fill(.background))
    }
    var shape: RoundedRectangle { RoundedRectangle(cornerRadius: 20) }
}

See Also 参照

Masks and Clipping