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

padding(_:)

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

Declaration 宣言

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

Return Value 戻り値

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

Parameters パラメータ

insets

An EdgeInsets instance that contains padding amounts for 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:

A screenshot of two text strings arranged vertically, each surrounded

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(_:).