Modifiers
gridCellAnchor
Specifies a custom alignment anchor for a view that acts as a grid cell.
gridCellAnchor(anchor)
iOS 16+
| Parameter | Type | Description |
|---|---|---|
anchor | { anchor: 'center' | 'top' | 'bottom' | 'leading' | 'trailing' | 'topLeading' | 'topTrailing' | 'bottomLeading' | 'bottomTrailing' | 'zero', type: 'preset' } | { points: { x: number, y: number }, type: 'custom' } | The unit point that defines how to align the view within the bounds of its grid cell. |
Specifies a custom alignment anchor for a view that acts as a grid cell.
Returns: ModifierConfig
A view that uses the specified anchor point to align its content.
Example
// Using a preset anchor
<Rectangle
modifiers={[
gridCellAnchor({ type: 'preset', anchor: 'center' }),
]}
/>
// Using a custom anchor point
<Rectangle
modifiers={[
gridCellAnchor({ type: 'custom', points: { x: 0.3, y: 0.8 } }),
]}
/>Works with
This modifier works with any view. These components accept it:
- VStack
- HStack
- ZStack
- LazyVStack
- LazyHStack
- Group
- Spacer
- Divider
- 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
Sources
The original Expo docs for this page:
- gridCellAnchor (Modifiers) (
source-of-truth/versions/v57.0.0/sdk/ui/swift-ui/modifiers.md)