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 UIKit and AppKit. It provides several classes to control the layout of text, including NSTextLayoutManager, NSTextContentStorage, NSTextViewportLayoutController, and NSTextContainer.

In UIKit, you can use UITextView, which packages TextKit capabilities to provide a convenient text rendering and editing experience. UITextView 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 UIView or CALayer 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 UITextView, access the TextKit engine through the view’s textLayoutManager, textContainer, and textStorage properties. UITextView 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 UIKit and AppKit, the same techniques apply across iOS, iPadOS, macOS, tvOS, and visionOS.

Topics

Text management

Formatting and attributes

Tables

Content elements

Location and selection

Layout

Attachments

TextKit 1

See Also

Text