<!--
{
  "documentType" : "article",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/textkit",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "TextKit"
}
-->

# TextKit

Manage text storage and perform custom layout of text-based content in your app’s views.

## Discussion

TextKit is a powerful and versatile text layout and rendering engine available in UIKit and AppKit. It provides several classes to control the layout of text, including [`NSTextLayoutManager`](/documentation/UIKit/NSTextLayoutManager), [`NSTextContentStorage`](/documentation/UIKit/NSTextContentStorage), [`NSTextViewportLayoutController`](/documentation/UIKit/NSTextViewportLayoutController), and [`NSTextContainer`](/documentation/UIKit/NSTextContainer).

In UIKit, you can use [`UITextView`](/documentation/UIKit/UITextView), which packages TextKit capabilities to provide a convenient text rendering and editing experience. [`UITextView`](/documentation/UIKit/UITextView) uses [`NSTextContentStorage`](/documentation/UIKit/NSTextContentStorage) as the text backing store manager. [`NSTextContentStorage`](/documentation/UIKit/NSTextContentStorage) uses an instance of [`NSTextStorage`](/documentation/UIKit/NSTextStorage) as the backing store, which is a subclass of <doc://com.apple.documentation/documentation/Foundation/NSMutableAttributedString>. For an example, see [Enriching your text in text views](/documentation/UIKit/enriching-your-text-in-text-views).

Alternatively, you can build custom text views using your own `UIView` or `CALayer` by rendering text provided by the TextKit text engine. Use [`NSTextContentStorage`](/documentation/UIKit/NSTextContentStorage) if you want an <doc://com.apple.documentation/documentation/Foundation/NSAttributedString>-related storage type, or subclass [`NSTextContentManager`](/documentation/UIKit/NSTextContentManager) to use your own. For an example, see [Using TextKit 2 to interact with text](/documentation/UIKit/using-textkit-2-to-interact-with-text).

When using [`UITextView`](/documentation/UIKit/UITextView), access the TextKit engine through the view’s [`textLayoutManager`](/documentation/UIKit/UITextView/textLayoutManager), [`textContainer`](/documentation/UIKit/UITextView/textContainer), and [`textStorage`](/documentation/UIKit/UITextView/textStorage) properties. [`UITextView`](/documentation/UIKit/UITextView) provides access to two layout engines: the modern [`textLayoutManager`](/documentation/UIKit/UITextView/textLayoutManager), which uses [`NSTextLayoutManager`](/documentation/UIKit/NSTextLayoutManager), and the legacy [`layoutManager`](/documentation/UIKit/UITextView/layoutManager), which uses [`NSLayoutManager`](/documentation/UIKit/NSLayoutManager). Use [`textLayoutManager`](/documentation/UIKit/UITextView/textLayoutManager) for better performance, and support for international languages. Because TextKit classes are available in both UIKit and AppKit, the same techniques apply across iOS, iPadOS, macOS, tvOS, and visionOS.

## Topics

### Text management

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

A concrete object for managing your view’s text content and generating the text elements necessary for layout.

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

An abstract class that defines the interface and a default implementation for managing the text document contents.

  <doc://com.apple.documentation/documentation/Foundation/NSAttributedString>

  <doc://com.apple.documentation/documentation/Foundation/NSMutableAttributedString>

### Text management

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

A concrete object for managing your view’s text content and generating the text elements necessary for layout.

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

An abstract class that defines the interface and a default implementation for managing the text document contents.

  <doc://com.apple.documentation/documentation/Foundation/NSAttributedString>

  <doc://com.apple.documentation/documentation/Foundation/NSMutableAttributedString>

[TextKit string attributes](/documentation/UIKit/textkit-string-attributes)

UIKit-specific keys and values for displaying text and managing documents.

### Formatting and attributes

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

The paragraph or ruler attributes for an attributed string.

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

An object for changing the values of the subattributes in a paragraph style attribute.

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

A tab in a paragraph.

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

A section of text that forms a single list.

[Adding tables to attributed strings in UIKit](/documentation/UIKit/adding-tables-to-attributed-strings)

Create and configure tables in attributed strings and display them in a text view.

### Tables

[Adding tables to attributed strings in UIKit](/documentation/UIKit/adding-tables-to-attributed-strings)

Create and configure tables in attributed strings and display them in a text view.

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

An object that represents a table of rows and columns in an attributed string.

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

A text block that represents a single cell in a text table.

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

An object that defines the size, spacing, and appearance of a block of text in an attributed string.

### Content elements

[Enriching your text in text views](/documentation/UIKit/enriching-your-text-in-text-views)

Support line numbering, section collapsing, inline attachment caching, exclusion paths, text attachments, and text lists in a text view.

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

A class that represents a single paragraph backed by an attributed string as the contents.

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

A class that represents a text list node.

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

An abstract base class that represents the smallest units of text layout such as paragraphs or attachments.

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

A protocol the text content manager and its concrete subclasses conform to, which defines the interface for interacting with custom content types of a text document.

### Location and selection

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

A class that represents a contiguous range between two locations inside document contents.

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

A class that represents a single logical selection context that corresponds to an insertion point.

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

An interface you use to expose methods for obtaining results from actions performed on text selections.

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

An interface you implement that represents an abstract location inside your document’s content.

### Layout

[Using TextKit 2 to interact with text](/documentation/UIKit/using-textkit-2-to-interact-with-text)

Interact with text by managing text selection and inserting custom text elements.

[Display text with a custom layout](/documentation/UIKit/display-text-with-a-custom-layout)

Lay out text in a custom-shaped container and apply glyph substitutions.

[Managing viewport layout and attachment reuse in text views](/documentation/UIKit/managing-viewport-layout-and-attachment-reuse-in-a-text-view-subclass)

Customize layout and preserve attachment views in your text view subclass.

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

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

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

A region where text layout occurs.

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

A class that represents the layout fragment typically corresponding to a rendering surface, such as a layer or view subclass.

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

A class that represents a line fragment as a single textual layout and rendering unit inside a text layout fragment.

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

Manages the layout process inside the viewport interacting with its delegate.

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

A protocol that identifies a view or layer as a drawable element for a text layout fragment.

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

A protocol that lets you use an object to identify a rendering surface when storing or retrieving it.

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

A set of methods that define the orientation of text for an object.

### Attachments

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

The values for the attachment characteristics of attributed strings and related objects.

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

A container object that associates a text attachment at a particular document location with a view object.

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

A data object for an emoji-like image that can appear in attributed text.

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

A set of methods that defines the interface to text attachment objects from a layout manager.

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

A set of methods that defines the interface to attachment objects from a text layout manager.

### TextKit 1

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

The fundamental storage mechanism of TextKit that contains the text managed by the system.

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

An object that coordinates the layout and display of text characters.



---

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)