<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/alignmentGuide(_:computeValue:)-6y3u2",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE14alignmentGuide_12computeValueQrAA17VerticalAlignmentV_14CoreFoundation7CGFloatVAA0C10DimensionsVctF"
  },
  "title" : "alignmentGuide(_:computeValue:)"
}
-->

# alignmentGuide(_:computeValue:)

Sets the view’s vertical alignment.

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

## Parameters

`g`

A `VerticalAlignment` value at which to base the offset.

`computeValue`

A closure that returns the offset value to apply to
this view.

## Return Value

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

## 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 weather emoji are offset 20 points from the
vertical center of the `HStack`.

```
VStack {
    Text("Today's Weather")
        .font(.title)
        .border(.gray)

    HStack {
        Text("🌧")
            .alignmentGuide(VerticalAlignment.center) { _ in -20 }
            .border(.gray)
        Text("Rain & Thunderstorms")
            .border(.gray)
        Text("⛈")
            .alignmentGuide(VerticalAlignment.center) { _ in 20 }
            .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.

![A view showing the two emoji offset from a text element using a](images/com.apple.SwiftUI/SwiftUI-View-VAlignmentGuide@2x.png)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)