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

padding(_:)

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

Declaration 宣言

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

Return Value 戻り値

A view that’s padded by the amount you specify.

Parameters パラメータ

length

The amount, given in points, to pad this view on all edges.

Discussion 議論

Use this modifier to add padding all the way around a view.


VStack {
    Text("Text padded by 10 points on each edge.")
        .padding(10)
        .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 independently control the amount of padding for each edge, use padding(_:). To pad a select set of edges by the same amount, use padding(_:_:).