Padding
Add space around a widget.
Overview
Padding creates empty space around its child widget. It’s one of the most commonly used widgets for creating visual breathing room in layouts.
Basic Usage
// All sides equal
Padding(.all(16)) {
Text("Padded Text")
}
// Or use the modifier
Text("Padded Text")
.padding(.all(16)) Padding Examples
EdgeInsets Options
All Sides Equal
.padding(.all(20)) // 20px on all sides Symmetric
.padding(.symmetric(horizontal: 20, vertical: 10))
// horizontal: left and right
// vertical: top and bottom Individual Sides
.padding(.only(
left: 10,
top: 20,
right: 10,
bottom: 20
)) You can omit sides to keep them at 0:
.padding(.only(left: 20, right: 20)) // top and bottom are 0
.padding(.only(bottom: 16)) // only bottom padding Parameters
| Parameter | Type | Description |
|---|---|---|
padding | EdgeInsets | Amount of space to add |
child | Widget | The widget to pad |