<!--
{
  "availability" : [
    "macOS: 10.9.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSStackView/Gravity",
  "metadataVersion" : "0.1.0",
  "role" : "Enumeration",
  "symbol" : {
    "kind" : "Enumeration",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:@E@NSStackViewGravity"
  },
  "title" : "NSStackView.Gravity"
}
-->

# NSStackView.Gravity

The gravity areas available in a stack view.

```
enum Gravity
```

## Overview

The layout of a stack view is partitioned into three distinct areas in which you can place views. These are known as *gravity areas*. You can use these constants to configure a stack view by way of the [`insertView(_:at:in:)`](/documentation/AppKit/NSStackView/insertView(_:at:in:)) and [`setViews(_:in:)`](/documentation/AppKit/NSStackView/setViews(_:in:)) methods.

In a horizontally oriented stack view, the three gravity areas are [`leading`](/documentation/AppKit/NSStackView/Gravity/leading), [`NSStackView.Gravity.center`](/documentation/AppKit/NSStackView/Gravity/center), and [`trailing`](/documentation/AppKit/NSStackView/Gravity/trailing). The ordering of these areas depends on the user interface language, unless you’ve explicitly specified the stack view’s user interface layout direction by calling the inherited [`userInterfaceLayoutDirection`](/documentation/AppKit/NSView/userInterfaceLayoutDirection) method. For a [`userInterfaceLayoutDirection`](/documentation/AppKit/NSView/userInterfaceLayoutDirection) property value of [`NSUserInterfaceLayoutDirection.leftToRight`](/documentation/AppKit/NSUserInterfaceLayoutDirection/leftToRight), the leading gravity area is on the left.

In a vertically oriented stack view, the three gravity areas are always [`NSStackView.Gravity.top`](/documentation/AppKit/NSStackView/Gravity/top), [`NSStackView.Gravity.center`](/documentation/AppKit/NSStackView/Gravity/center), and [`NSStackView.Gravity.bottom`](/documentation/AppKit/NSStackView/Gravity/bottom).

The center gravity area is constrained to remain geometrically centered with an Auto Layout priority of [`defaultLow`](/documentation/AppKit/NSLayoutConstraint/Priority-swift.struct/defaultLow). For information about geometric spacing between gravity areas, see the description of the [`spacing`](/documentation/AppKit/NSStackView/spacing) property.

## Topics

### Constants

[`NSStackView.Gravity.top`](/documentation/AppKit/NSStackView/Gravity/top)

The topmost gravity area in a vertically oriented stack view.

[`leading`](/documentation/AppKit/NSStackView/Gravity/leading)

The leftmost or rightmost gravity area in a horizontally oriented stack view, based on the user interface language or the explicitly set user interface layout direction.

[`NSStackView.Gravity.center`](/documentation/AppKit/NSStackView/Gravity/center)

The center gravity area, regardless of stack view layout direction or user interface language.

[`NSStackView.Gravity.bottom`](/documentation/AppKit/NSStackView/Gravity/bottom)

The bottommost gravity area in a vertically oriented stack view.

[`trailing`](/documentation/AppKit/NSStackView/Gravity/trailing)

The leftmost or rightmost gravity area in a horizontally oriented stack view, based on the user interface language or the explicitly set user interface layout direction.



---

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)