<!--
{
  "documentType" : "article",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/layout",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "Layout"
}
-->

# Layout

Specify the size and position your view relative to other nearby views using rules that update your view hierarchy automatically.

## Topics

### Respecting the View’s Safe Area

[`safeAreaRect`](/documentation/AppKit/NSView/safeAreaRect)

A rectangle in the view’s coordinate system that contains the unobscured portion of the view.

[`safeAreaInsets`](/documentation/AppKit/NSView/safeAreaInsets)

The distances from the edges of your view that define the safe area.

[`additionalSafeAreaInsets`](/documentation/AppKit/NSView/additionalSafeAreaInsets)

Custom insets that you specify to modify your view’s safe area

[`safeAreaLayoutGuide`](/documentation/AppKit/NSView/safeAreaLayoutGuide)

The layout guide you use to position content inside your view’s safe area.

### Managing the Content Layout Direction

[`userInterfaceLayoutDirection`](/documentation/AppKit/NSView/userInterfaceLayoutDirection)

The layout direction for content in the view.

### Opting In to Auto Layout

[`requiresConstraintBasedLayout`](/documentation/AppKit/NSView/requiresConstraintBasedLayout)

Returns a Boolean value indicating whether the view depends on the constraint-based layout system.

[`translatesAutoresizingMaskIntoConstraints`](/documentation/AppKit/NSView/translatesAutoresizingMaskIntoConstraints)

A Boolean value indicating whether the view’s autoresizing mask is translated into constraints for the constraint-based layout system.

### Creating Constraints Using Layout Anchors

[`bottomAnchor`](/documentation/AppKit/NSView/bottomAnchor)

A layout anchor representing the bottom edge of the view’s frame.

[`centerXAnchor`](/documentation/AppKit/NSView/centerXAnchor)

A layout anchor representing the horizontal center of the view’s frame.

[`centerYAnchor`](/documentation/AppKit/NSView/centerYAnchor)

A layout anchor representing the vertical center of the view’s frame.

[`firstBaselineAnchor`](/documentation/AppKit/NSView/firstBaselineAnchor)

A layout anchor representing the baseline for the topmost line of text in the view.

[`heightAnchor`](/documentation/AppKit/NSView/heightAnchor)

A layout anchor representing the height of the view’s frame.

[`lastBaselineAnchor`](/documentation/AppKit/NSView/lastBaselineAnchor)

A layout anchor representing the baseline for the bottommost line of text in the view.

[`leadingAnchor`](/documentation/AppKit/NSView/leadingAnchor)

A layout anchor representing the leading edge of the view’s frame.

[`leftAnchor`](/documentation/AppKit/NSView/leftAnchor)

A layout anchor representing the left edge of the view’s frame.

[`rightAnchor`](/documentation/AppKit/NSView/rightAnchor)

A layout anchor representing the right edge of the view’s frame.

[`topAnchor`](/documentation/AppKit/NSView/topAnchor)

A layout anchor representing the top edge of the view’s frame.

[`trailingAnchor`](/documentation/AppKit/NSView/trailingAnchor)

A layout anchor representing the trailing edge of the view’s frame.

[`widthAnchor`](/documentation/AppKit/NSView/widthAnchor)

A layout anchor representing the width of the view’s frame.

### Managing the View’s Constraints

[`constraints`](/documentation/AppKit/NSView/constraints)

Returns the constraints held by the view.

[`-  addConstraint:`](/documentation/AppKit/NSView/addConstraint(_:))

Adds a constraint on the layout of the receiving view or its subviews.

[`-  addConstraints:`](/documentation/AppKit/NSView/addConstraints(_:))

Adds multiple constraints on the layout of the receiving view or its subviews.

[`-  removeConstraint:`](/documentation/AppKit/NSView/removeConstraint(_:))

Removes the specified constraint from the view.

[`-  removeConstraints:`](/documentation/AppKit/NSView/removeConstraints(_:))

Removes the specified constraints from the view.

### Measuring in Auto Layout

[`fittingSize`](/documentation/AppKit/NSView/fittingSize)

The minimum size of the view that satisfies the constraints it holds.

[`intrinsicContentSize`](/documentation/AppKit/NSView/intrinsicContentSize)

The natural size for the receiving view, considering only properties of the view itself.

[`-  invalidateIntrinsicContentSize`](/documentation/AppKit/NSView/invalidateIntrinsicContentSize())

Invalidates the view’s intrinsic content size.

[`-  contentCompressionResistancePriorityForOrientation:`](/documentation/AppKit/NSView/contentCompressionResistancePriority(for:))

Returns the priority with which a view resists being made smaller than its intrinsic size.

[`-  setContentCompressionResistancePriority:forOrientation:`](/documentation/AppKit/NSView/setContentCompressionResistancePriority(_:for:))

Sets the priority with which a view resists being made smaller than its intrinsic size.

[`-  contentHuggingPriorityForOrientation:`](/documentation/AppKit/NSView/contentHuggingPriority(for:))

Returns the priority with which a view resists being made larger than its intrinsic size.

[`-  setContentHuggingPriority:forOrientation:`](/documentation/AppKit/NSView/setContentHuggingPriority(_:for:))

Sets the priority with which a view resists being made larger than its intrinsic size.

[`NSViewNoIntrinsicMetric`](/documentation/AppKit/NSView/noIntrinsicMetric)

A value that tells the layout system to ignore the intrinsic size value for a given dimension.

### Managing Layout Guides

[`-  addLayoutGuide:`](/documentation/AppKit/NSView/addLayoutGuide(_:))

Adds the provided layout guide to the view.

[`-  removeLayoutGuide:`](/documentation/AppKit/NSView/removeLayoutGuide(_:))

Removes the provided layout guide from the view.

[`layoutGuides`](/documentation/AppKit/NSView/layoutGuides)

The array of layout guide objects owned by this view.

[`layoutMarginsGuide`](/documentation/AppKit/NSView/layoutMarginsGuide)

A layout guide that provides the recommended amount of padding for content inside of a view.

### Aligning Views with Auto Layout

[`-  alignmentRectForFrame:`](/documentation/AppKit/NSView/alignmentRect(forFrame:))

Returns the view’s alignment rectangle for a given frame.

[`-  frameForAlignmentRect:`](/documentation/AppKit/NSView/frame(forAlignmentRect:))

Returns the view’s frame for a given alignment rectangle.

[`alignmentRectInsets`](/documentation/AppKit/NSView/alignmentRectInsets)

The insets (in points) from the view’s frame that define its content rectangle.

[`baselineOffsetFromBottom`](/documentation/AppKit/NSView/baselineOffsetFromBottom)

The distance (in points) between the bottom of the view’s alignment rectangle and its baseline.

[`firstBaselineOffsetFromTop`](/documentation/AppKit/NSView/firstBaselineOffsetFromTop)

The distance (in points) between the top of the view’s alignment rectangle and its topmost baseline.

[`lastBaselineOffsetFromBottom`](/documentation/AppKit/NSView/lastBaselineOffsetFromBottom)

The distance (in points) between the bottom of the view’s alignment rectangle and its bottommost baseline.

### Triggering Auto Layout

[`needsLayout`](/documentation/AppKit/NSView/needsLayout)

A Boolean value indicating whether the view needs a layout pass before it can be drawn.

[`-  layout`](/documentation/AppKit/NSView/layout())

Perform layout in concert with the constraint-based layout system.

[`-  layoutSubtreeIfNeeded`](/documentation/AppKit/NSView/layoutSubtreeIfNeeded())

Updates the layout of the receiving view and its subviews based on the current views and constraints.

[`needsUpdateConstraints`](/documentation/AppKit/NSView/needsUpdateConstraints)

A Boolean value indicating whether the view’s constraints need to be updated.

[`-  updateConstraints`](/documentation/AppKit/NSView/updateConstraints())

Update constraints for the view.

[`-  updateConstraintsForSubtreeIfNeeded`](/documentation/AppKit/NSView/updateConstraintsForSubtreeIfNeeded())

Updates the constraints for the receiving view and its subviews.

### Enabling and Disabling Constraints

[`horizontalContentSizeConstraintActive`](/documentation/AppKit/NSView/isHorizontalContentSizeConstraintActive)

A Boolean value that indicates whether the view’s horizontal size constraints are active.

[`verticalContentSizeConstraintActive`](/documentation/AppKit/NSView/isVerticalContentSizeConstraintActive)

A Boolean value that indicates whether the view’s vertical size constraints are active.

### Debugging Auto Layout

[`-  constraintsAffectingLayoutForOrientation:`](/documentation/AppKit/NSView/constraintsAffectingLayout(for:))

Returns the constraints impacting the layout of the view for a given orientation.

[`hasAmbiguousLayout`](/documentation/AppKit/NSView/hasAmbiguousLayout)

A Boolean value indicating whether the constraints impacting the layout of the view incompletely specify the location of the view.

[`-  exerciseAmbiguityInLayout`](/documentation/AppKit/NSView/exerciseAmbiguityInLayout())

Randomly changes the frame of a view with an ambiguous layout between the different valid values.

### Resizing Subviews

[`autoresizesSubviews`](/documentation/AppKit/NSView/autoresizesSubviews)

A Boolean value indicating whether the view applies the autoresizing behavior to its subviews when its frame size changes.

[`autoresizingMask`](/documentation/AppKit/NSView/autoresizingMask-swift.property)

The options that determine how the view is resized relative to its superview.

[`AutoresizingMask`](/documentation/AppKit/NSView/AutoresizingMask-swift.struct)

Constants that specify the autoresizing behaviors for views.

[`-  resizeSubviewsWithOldSize:`](/documentation/AppKit/NSView/resizeSubviews(withOldSize:))

Informs the view’s subviews that the view’s bounds rectangle size has changed.

[`-  resizeWithOldSuperviewSize:`](/documentation/AppKit/NSView/resize(withOldSuperviewSize:))

Informs the view that the bounds size of its superview has changed.



---

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)