<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/NSTextLayoutManager",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "UIKit"
    ],
    "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/UIKit/NSTextContainer) objects. It lays out results using [`NSTextLayoutFragment`](/documentation/UIKit/NSTextLayoutFragment) and [`NSTextElement`](/documentation/UIKit/NSTextElement) objects vended from a [`NSTextContentManager`](/documentation/UIKit/NSTextContentManager) that participates in the content layout process.

## Topics

### Creating a layout manager

[`init()`](/documentation/UIKit/NSTextLayoutManager/init())

Creates a new text layout manager.

[`init(coder:)`](/documentation/UIKit/NSTextLayoutManager/init(coder:))

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

### Configuring global layout manager options

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

The queue that the framework dispatches layout operations on.

[`renderingAttributesValidator`](/documentation/UIKit/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/UIKit/NSTextLayoutManager/usesFontLeading)

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

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

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

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

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

### Managing the layout process

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

The delegate for the text layout manager object.

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

Optional methods that delegates implement to respond to layout changes.

### Accessing the text storage

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

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

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

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

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

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

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

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

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

Returns the usage bounds for the text container.

[`enumerateTextSegments(in:type:options:using:)`](/documentation/UIKit/NSTextLayoutManager/enumerateTextSegments(in:type:options:using:))

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

[`replace(_:)`](/documentation/UIKit/NSTextLayoutManager/replace(_:))

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

[`replaceContents(in:with:)`](/documentation/UIKit/NSTextLayoutManager/replaceContents(in:with:)-2elb)

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

[`replaceContents(in:with:)`](/documentation/UIKit/NSTextLayoutManager/replaceContents(in:with:)-80j0b)

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

### Adjusting rendering

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

Returns the default set of attributes for rendering a link.

[`addRenderingAttribute(_:value:for:)`](/documentation/UIKit/NSTextLayoutManager/addRenderingAttribute(_:value:for:))

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

[`enumerateRenderingAttributes(from:reverse:using:)`](/documentation/UIKit/NSTextLayoutManager/enumerateRenderingAttributes(from:reverse:using:))

Enumerates the rendering attributes from a location you specify.

[`renderingAttributes(forLink:at:)`](/documentation/UIKit/NSTextLayoutManager/renderingAttributes(forLink:at:))

Returns a dictionary of rendering attributes for rendering a link.

[`invalidateRenderingAttributes(for:)`](/documentation/UIKit/NSTextLayoutManager/invalidateRenderingAttributes(for:))

Invalidates the rendering attributes of the specified text range.

[`removeRenderingAttribute(_:for:)`](/documentation/UIKit/NSTextLayoutManager/removeRenderingAttribute(_:for:))

Removes the rendering attribute from the specified text range.

[`setRenderingAttributes(_:for:)`](/documentation/UIKit/NSTextLayoutManager/setRenderingAttributes(_:for:))

Sets the rendering attributes for the range you specify.

### Causing layout generation

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

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

[`invalidateLayout(for:)`](/documentation/UIKit/NSTextLayoutManager/invalidateLayout(for:))

Invalidates the layout information for specified text range.

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

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

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

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

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

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

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

Performs the layout for specified text range.

[`enumerateTextLayoutFragments(from:options:using:)`](/documentation/UIKit/NSTextLayoutManager/enumerateTextLayoutFragments(from:options:using:))

Enumerates the text layout fragments starting at the specified location.

[`NSTextLayoutManager.SegmentType`](/documentation/UIKit/NSTextLayoutManager/SegmentType)

Values that describe the rendering of selection boundaries.

[`NSTextLayoutManager.SegmentOptions`](/documentation/UIKit/NSTextLayoutManager/SegmentOptions)

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



---

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)