Contents

TextKit

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

Overview

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

In AppKit, you can use NSTextView, which packages TextKit capabilities to provide a convenient text rendering and editing experience. NSTextView uses NSTextContentStorage as the text backing store manager. NSTextContentStorage uses an instance of NSTextStorage as the backing store, which is a subclass of NSMutableAttributedString. For an example, see Enriching your text in text views.

Alternatively, you can build custom text views using your own NSView by rendering text provided by the TextKit text engine. Use NSTextContentStorage if you want an NSAttributedString-related storage type, or subclass NSTextContentManager to use your own. For an example, see Using TextKit 2 to interact with text.

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

Topics

Text management

Formatting and attributes

Tables

Content elements

Location and selection

Layout

Attachments

Glyphs

TextKit 1

See Also

Text