---
title: "alignmentGuide(_:computeValue:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/view/alignmentguide(_:computevalue:)"
---

# alignmentGuide(_:computeValue:)

Sets the view’s horizontal alignment.

## Declaration

```swift
@preconcurrency nonisolated func alignmentGuide(_ g: HorizontalAlignment, computeValue: @escaping @Sendable (ViewDimensions) -> CGFloat) -> some View

```

## Parameters

- `g`: A doc://com.apple.SwiftUI/documentation/SwiftUI/HorizontalAlignment value at which to base the offset.
- `computeValue`: A closure that returns the offset value to apply to this view.

## Mentioned in

Aligning views across stacks Aligning views within a stack

## Return Value

Return Value A view modified with respect to its horizontal alignment according to the computation performed in the method’s closure.

## Discussion

Discussion Use alignmentGuide(_:computeValue:) to calculate specific offsets to reposition views in relationship to one another. You can return a constant or can use the ViewDimensions argument to the closure to calculate a return value. In the example below, the HStack is offset by a constant of 50 points to the right of center: VStack {     Text("Today's Weather")         .font(.title)         .border(.gray)     HStack {         Text("🌧")         Text("Rain & Thunderstorms")         Text("⛈")     }     .alignmentGuide(HorizontalAlignment.center) { _ in  50 }     .border(.gray) } .border(.gray) Changing the alignment of one view may have effects on surrounding views. Here the offset values inside a stack and its contained views is the difference of their absolute offsets.

## See Also

### Aligning views

- [Aligning views within a stack](swiftui/aligning-views-within-a-stack.md)
- [Aligning views across stacks](swiftui/aligning-views-across-stacks.md)
- [Alignment](swiftui/alignment.md)
- [HorizontalAlignment](swiftui/horizontalalignment.md)
- [VerticalAlignment](swiftui/verticalalignment.md)
- [DepthAlignment](swiftui/depthalignment.md)
- [AlignmentID](swiftui/alignmentid.md)
- [ViewDimensions](swiftui/viewdimensions.md)
- [ViewDimensions3D](swiftui/viewdimensions3d.md)
- [SpatialContainer](swiftui/spatialcontainer.md)
