<!--
{
  "availability" : [
    "macOS: 12.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextLayoutManager",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSTextLayoutManager"
  },
  "title" : "NSTextLayoutManager"
}
-->

# NSTextLayoutManager

The primary class that you use to manage text layout and presentation for custom text displays.

```
class NSTextLayoutManager
```

## Overview

`NSTextLayoutManager` is the centerpiece of the TextKit object network that maintains the layout geometry through an array of [`NSTextContainer`](/documentation/AppKit/NSTextContainer) objects. It lays out results using [`NSTextLayoutFragment`](/documentation/AppKit/NSTextLayoutFragment) and [`NSTextElement`](/documentation/AppKit/NSTextElement) objects vended from a [`NSTextContentManager`](/documentation/AppKit/NSTextContentManager) that participates in the content layout process.

## Topics

### Creating a layout manager

[`-  init`](/documentation/AppKit/NSTextLayoutManager/init())

Creates a new text layout manager.

[`-  initWithCoder:`](/documentation/AppKit/NSTextLayoutManager/init(coder:))

Creates a new text layout manager with the coder you provide.

### Configuring global layout manager options

[`layoutQueue`](/documentation/AppKit/NSTextLayoutManager/layoutQueue)

The queue that the framework dispatches layout operations on.

[`renderingAttributesValidator`](/documentation/AppKit/NSTextLayoutManager/renderingAttributesValidator)

A callback block that the framework invokes whenever the text layout manager needs to validate the rendering attributes for the range.

[`usesFontLeading`](/documentation/AppKit/NSTextLayoutManager/usesFontLeading)

A Boolean value that controls whether the framework uses the leading information specified by the font when laying out text.

[`usesHyphenation`](/documentation/AppKit/NSTextLayoutManager/usesHyphenation)

A Boolean values that controls whether the text layout manager attempts to hyphenate when wrapping lines.

[`limitsLayoutForSuspiciousContents`](/documentation/AppKit/NSTextLayoutManager/limitsLayoutForSuspiciousContents)

A Boolean value that controls internal security analysis for malicious inputs and activates defensive behaviors.

### Managing the layout process

[`delegate`](/documentation/AppKit/NSTextLayoutManager/delegate)

The delegate for the text layout manager object.

[`NSTextLayoutManagerDelegate`](/documentation/AppKit/NSTextLayoutManagerDelegate)

Optional methods that delegates implement to respond to layout changes.

### Accessing the text storage

[`textContentManager`](/documentation/AppKit/NSTextLayoutManager/textContentManager)

Returns the text content manager associated with this text layout manager.

[`textContainer`](/documentation/AppKit/NSTextLayoutManager/textContainer)

The text container object that provides geometric information for the layout destination.

[`textSelectionNavigation`](/documentation/AppKit/NSTextLayoutManager/textSelectionNavigation)

Returns a text selection manager configured to have the text layout manager as its data source.

[`textSelections`](/documentation/AppKit/NSTextLayoutManager/textSelections)

An array of text selections associated by the text layout manager.

[`usageBoundsForTextContainer`](/documentation/AppKit/NSTextLayoutManager/usageBoundsForTextContainer)

Returns the usage bounds for the text container.

[`-  enumerateTextSegmentsInRange:type:options:usingBlock:`](/documentation/AppKit/NSTextLayoutManager/enumerateTextSegments(in:type:options:using:))

Enumerates text segments of a specific type and in the text range you provide.

[`-  replaceTextContentManager:`](/documentation/AppKit/NSTextLayoutManager/replace(_:))

Replaces the current text content manager with a new one you provide.

[`-  replaceContentsInRange:withAttributedString:`](/documentation/AppKit/NSTextLayoutManager/replaceContents(in:with:)-2elb)

Replaces content at the location you specify with an attributed string you provide.

[`-  replaceContentsInRange:withTextElements:`](/documentation/AppKit/NSTextLayoutManager/replaceContents(in:with:)-80j0b)

Replaces content at the location you specify with the text elements string you provide.

### Adjusting rendering

[`linkRenderingAttributes`](/documentation/AppKit/NSTextLayoutManager/linkRenderingAttributes)

Returns the default set of attributes for rendering a link.

[`-  addRenderingAttribute:value:forTextRange:`](/documentation/AppKit/NSTextLayoutManager/addRenderingAttribute(_:value:for:))

Sets the rendering attribute for the value and range you specify.

[`-  enumerateRenderingAttributesFromLocation:reverse:usingBlock:`](/documentation/AppKit/NSTextLayoutManager/enumerateRenderingAttributes(from:reverse:using:))

Enumerates the rendering attributes from a location you specify.

[`-  renderingAttributesForLink:atLocation:`](/documentation/AppKit/NSTextLayoutManager/renderingAttributes(forLink:at:))

Returns a dictionary of rendering attributes for rendering a link.

[`-  invalidateRenderingAttributesForTextRange:`](/documentation/AppKit/NSTextLayoutManager/invalidateRenderingAttributes(for:))

Invalidates the rendering attributes of the specified text range.

[`-  removeRenderingAttribute:forTextRange:`](/documentation/AppKit/NSTextLayoutManager/removeRenderingAttribute(_:for:))

Removes the rendering attribute from the specified text range.

[`-  setRenderingAttributes:forTextRange:`](/documentation/AppKit/NSTextLayoutManager/setRenderingAttributes(_:for:))

Sets the rendering attributes for the range you specify.

### Causing layout generation

[`textViewportLayoutController`](/documentation/AppKit/NSTextLayoutManager/textViewportLayoutController)

The text viewport layout controller associated with the layout manager’s text container.

[`-  invalidateLayoutForRange:`](/documentation/AppKit/NSTextLayoutManager/invalidateLayout(for:))

Invalidates the layout information for specified text range.

[`-  textLayoutFragmentForLocation:`](/documentation/AppKit/NSTextLayoutManager/textLayoutFragment(for:)-68dez)

Returns the text layout fragment from the document at the specified location.

[`-  textLayoutFragmentForPosition:`](/documentation/AppKit/NSTextLayoutManager/textLayoutFragment(for:)-4dhrx)

Returns the text layout fragment at the position you specify in the text container.

[`-  ensureLayoutForBounds:`](/documentation/AppKit/NSTextLayoutManager/ensureLayout(for:)-6ptsj)

Performs the layout for filling the bounds you specify inside the last text container.

[`-  ensureLayoutForRange:`](/documentation/AppKit/NSTextLayoutManager/ensureLayout(for:)-3duae)

Performs the layout for specified text range.

[`-  enumerateTextLayoutFragmentsFromLocation:options:usingBlock:`](/documentation/AppKit/NSTextLayoutManager/enumerateTextLayoutFragments(from:options:using:))

Enumerates the text layout fragments starting at the specified location.

[`SegmentType`](/documentation/AppKit/NSTextLayoutManager/SegmentType)

Values that describe the rendering of selection boundaries.

[`SegmentOptions`](/documentation/AppKit/NSTextLayoutManager/SegmentOptions)

Values that describe where and how the framework extends segments of a selection.

## Relationships

### Conforms To

[`Equatable`](/documentation/Swift/Equatable)

[`NSTextSelectionDataSource`](/documentation/AppKit/NSTextSelectionDataSource)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Hashable`](/documentation/Swift/Hashable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

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)