Class

NSTextContainer

The NSTextContainer class defines a region where text is laid out. An NSLayoutManager uses NSTextContainer to determine where to break lines, lay out portions of text, and so on. An NSTextContainer object normally defines rectangular regions, but you can define exclusion paths inside the text container to create regions where text does not flow. You can also subclass to create text containers with nonrectangular regions, such as circular regions, regions with holes in them, or regions that flow alongside graphics.

Overview

Instances of the NSTextContainer, NSLayoutManager, and NSTextStorage classes can be accessed from threads other than the main thread as long as the app guarantees access from only one thread at a time.

Symbols

Creating a Text Container

init(size: CGSize)

Initializes a text container with a specified bounding rectangle.

Managing Text Components

var layoutManager: NSLayoutManager?

The receiver’s layout manager.

func replaceLayoutManager(NSLayoutManager)

Replaces the layout manager for the group of text system objects containing the receiver.

var textView: NSTextView?

The receiver’s text view.

Defining the Container Shape

var size: CGSize

The size of the text container’s bounding rectangle.

var exclusionPaths: [UIBezierPath]

An array of path objects representing the regions where text is not displayed in the text container.

var lineBreakMode: NSLineBreakMode

The behavior of the last line inside the text container.

var containerSize: NSSize

The size of the receiver’s bounding rectangle.

Deprecated
var widthTracksTextView: Bool

A Boolean that controls whether the receiver adjusts the width of its bounding rectangle when its text view is resized.

var heightTracksTextView: Bool

A Boolean that controls whether the receiver adjusts the height of its bounding rectangle when its text view is resized.

Constraining Text Layout

var maximumNumberOfLines: Int

The maximum number of lines that can be stored in the text container.

var lineFragmentPadding: CGFloat

The amount by which text is inset within line fragment rectangles.

func lineFragmentRect(forProposedRect: CGRect, at: Int, writingDirection: NSWritingDirection, remaining: UnsafeMutablePointer<CGRect>?)

Returns the bounds of a line fragment rectangle inside the receiver for the proposed rectangle.

var isSimpleRectangularTextContainer: Bool

A boolean that indicates whether the receiver’s region is a rectangle with no holes or gaps and whose edges are parallel to the text view's coordinate system axes.

Deprecated

init(containerSize: NSSize)

Initializes a text container with a specified bounding rectangle.

Deprecated
func lineFragmentRect(forProposedRect: NSRect, sweepDirection: NSLineSweepDirection, movementDirection: NSLineMovementDirection, remaining: NSRectPointer?)

Overridden by subclasses to calculate and return the longest rectangle available in the proposed rectangle for displaying text, or NSZeroRect if there is none according to the receiver’s region definition.

Deprecated
func contains(NSPoint)

Overridden by subclasses to return whether a point lies within the receiver’s region or on the region’s edge—not simply within its bounding rectangle.

Deprecated

Constants

NSLineSweepDirection

These constants describe the progression of text on a page. The typesetter decides which way text is supposed to flow and passes these values as arguments to the text container, which uses them to calculate the next line rectangle.

NSLineMovementDirection

Line movement is the direction in which lines move. See Text System Storage Layer Overview.