---
title: NSTextContainer
framework: appkit
role: symbol
role_heading: Class
path: appkit/nstextcontainer
---

# NSTextContainer

A region where text layout occurs.

## Declaration

```swift
class NSTextContainer
```

## Overview

Overview An NSLayoutManager uses NSTextContainer to determine where to break lines, lay out portions of text, and so on. An NSTextContainer object typically defines rectangular regions, but you can define exclusion paths inside the text container to create regions where text doesn’t 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. You can access instances of the NSTextContainer, NSLayoutManager, and NSTextStorage classes from threads other than the main thread as long as the app guarantees access from only one thread at a time.

## Topics

### Creating a text container

- [init(size:)](appkit/nstextcontainer/init(size:).md)
- [init(coder:)](appkit/nstextcontainer/init(coder:).md)

### Managing text components

- [layoutManager](appkit/nstextcontainer/layoutmanager.md)
- [textLayoutManager](appkit/nstextcontainer/textlayoutmanager.md)
- [replaceLayoutManager(_:)](appkit/nstextcontainer/replacelayoutmanager(_:).md)
- [textView](appkit/nstextcontainer/textview.md)

### Defining the container shape

- [size](appkit/nstextcontainer/size.md)
- [exclusionPaths](appkit/nstextcontainer/exclusionpaths.md)
- [lineBreakMode](appkit/nstextcontainer/linebreakmode.md)
- [widthTracksTextView](appkit/nstextcontainer/widthtrackstextview.md)
- [heightTracksTextView](appkit/nstextcontainer/heighttrackstextview.md)

### Constraining text layout

- [maximumNumberOfLines](appkit/nstextcontainer/maximumnumberoflines.md)
- [lineFragmentPadding](appkit/nstextcontainer/linefragmentpadding.md)
- [lineFragmentRect(forProposedRect:at:writingDirection:remaining:)](appkit/nstextcontainer/linefragmentrect(forproposedrect:at:writingdirection:remaining:).md)
- [isSimpleRectangularTextContainer](appkit/nstextcontainer/issimplerectangulartextcontainer.md)

### Deprecated

- [init(containerSize:)](appkit/nstextcontainer/init(containersize:).md)
- [lineFragmentRect(forProposedRect:sweepDirection:movementDirection:remaining:)](appkit/nstextcontainer/linefragmentrect(forproposedrect:sweepdirection:movementdirection:remaining:).md)
- [contains(_:)](appkit/nstextcontainer/contains(_:).md)
- [containerSize](appkit/nstextcontainer/containersize.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)
- [NSTextLayoutOrientationProvider](appkit/nstextlayoutorientationprovider.md)

## See Also

### Layout

- [Using TextKit 2 to interact with text](uikit/using-textkit-2-to-interact-with-text.md)
- [NSTextLayoutManager](appkit/nstextlayoutmanager.md)
- [NSTextLayoutFragment](appkit/nstextlayoutfragment.md)
- [NSTextLineFragment](appkit/nstextlinefragment.md)
- [NSTextViewportLayoutController](appkit/nstextviewportlayoutcontroller.md)
- [NSTextLayoutOrientationProvider](appkit/nstextlayoutorientationprovider.md)
