Contents

padding(_:)

Adds a different padding amount to each edge of this view.

Declaration

nonisolated func padding(_ insets: EdgeInsets) -> some View

Parameters

  • insets:

    An Edgeinsets instance that contains padding amounts for each edge.

Return Value

A view that’s padded by different amounts on each edge.

Discussion

Use this modifier to add a different amount of padding on each edge of a view:

VStack {
    Text("Text padded by different amounts on each edge.")
        .padding(EdgeInsets(top: 10, leading: 20, bottom: 40, trailing: 0))
        .border(.gray)
    Text("Unpadded text for comparison.")
        .border(.yellow)
}

The order in which you apply modifiers matters. The example above applies the padding before applying the border to ensure that the border encompasses the padded region:

[Image]

To pad a view on specific edges with equal padding for all padded edges, use padding(_:_:). To pad all edges of a view equally, use padding(_:).

See Also

Adding padding around a view