Instance Method

padding(_:)

Pads the view along all edges by the specified amount.

Declaration

func padding(_ length: CGFloat) -> some View

Parameters

length

The amount to pad this view on each edge.

Return Value

A view that pads this view by the amount you specify.

Discussion

Use padding(_:) to add a specific amount of padding around all edges of the view.

VStack {
    Text("Text padded by 10 points on each edge.")
        .padding(10.0)
        .border(Color.gray)
    Text("Unpadded text")
        .border(Color.yellow)
}
A view showing 10 points of padding to all edges.

See Also

Adjusting the Padding of a View

func padding(EdgeInsets) -> View

Pads this view using a system default amount inside the edges you specify.

func padding(Edge.Set, CGFloat?) -> View

A view that pads this view inside the specified edge insets with a system-calculated amount of padding.

struct EdgeInsets

The inset distances for the sides of a rectangle.