Modifiers
frame
Sets the frame properties of a view.
frame(params)
| Parameter | Type | Description |
|---|---|---|
params | { alignment: 'center' | 'top' | 'bottom' | 'leading' | 'trailing' | 'topLeading' | 'topTrailing' | 'bottomLeading' | 'bottomTrailing', height: number, idealHeight: number, idealWidth: number, maxHeight: number, maxWidth: number, minHeight: number, minWidth: number, width: number } | The frame parameters. Width, height, minWidth, maxWidth, minHeight, maxHeight, idealWidth, idealHeight and alignment. |
Sets the frame properties of a view.
Returns: ModifierConfig
See: Official SwiftUI documentation.
Works with
You can add frame to any view. It changes what you see on 39 of the 39 components.
- VStack
- HStack
- ZStack
- LazyVStack
- LazyHStack
- Group
- Overlay
- ScrollView
- Button
- Toggle
- Checkbox
- Slider
- Picker
- DatePicker
- ColorPicker
- Link
- ControlGroup
- Menu
- ContextMenu
- TextField
- SecureField
- Text
- Label
- Image
- List
- Form
- Section
- 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 |
|---|---|
| Spacer | Use minWidth or minHeight to give the spacer a smallest size. A fixed size stops it from growing. |
| Divider | Set the height for a horizontal divider, or the width for a vertical one. The other side fills the parent. |
Sources
The original Expo docs for this page:
- frame (Modifiers) (
source-of-truth/versions/v57.0.0/sdk/ui/swift-ui/modifiers.md)