Modifiers
padding
Sets padding on a view. Supports individual edges or shorthand properties.
padding(params)
| Parameter | Type | Description |
|---|---|---|
params(optional) | { all: number, bottom: number, horizontal: number, leading: number, top: number, trailing: number, vertical: number } | The padding parameters: top, bottom, leading, trailing, horizontal, vertical and all. |
Sets padding on a view. Supports individual edges or shorthand properties.
Returns: ModifierConfig
See: Official SwiftUI documentation.
Works with
You can add padding to any view. It changes what you see on 39 of the 39 components.
- VStack
- HStack
- ZStack
- LazyVStack
- LazyHStack
- Spacer
- Divider
- Overlay
- ScrollView
- Button
- Toggle
- Checkbox
- Slider
- Picker
- DatePicker
- ColorPicker
- Link
- ControlGroup
- Menu
- ContextMenu
- TextField
- SecureField
- Text
- Label
- Image
- List
- Form
- DisclosureGroup
- SwipeActions
- BottomSheet
- Alert
- ConfirmationDialog
- Popover
- ProgressView
- Gauge
- TabView
- AccessoryWidgetBackground
Needs care
It works on these components, but not in the way that you may expect.
| Component | What to know |
|---|---|
| Group | SwiftUI gives the padding to each child of the Group, not to the group as one view. |
| Section | It changes the whole section, not one row. For one row, put it on the view in the row. |
Sources
The original Expo docs for this page:
- padding (Modifiers) (
source-of-truth/versions/v57.0.0/sdk/ui/swift-ui/modifiers.md)