<!--
{
  "availability" : [
    "iOS: 7.0.0 -",
    "iPadOS: 7.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/NSTextContainer/init(size:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSTextContainer(im)initWithSize:"
  },
  "title" : "init(size:)"
}
-->

# init(size:)

Initializes a text container with a specified bounding rectangle.

```
init(size: CGSize)
```

## Parameters

`size`

The size of the text container’s bounding rectangle.

## Return Value

The size of the text container’s bounding rectangle.

## Discussion

The new text container must be added to an [`NSLayoutManager`](/documentation/UIKit/NSLayoutManager) object before it can be used. The text container must also have an associated <doc://com.apple.documentation/documentation/AppKit/NSTextView> object for text to be displayed. This method is the designated initializer for the `NSTextContainer` class.

## See Also

  [Text Layout Programming Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/TextLayout/TextLayout.html#//apple_ref/doc/uid/10000158i)

  [Cocoa Text Architecture Guide](https://developer.apple.com/library/archive/documentation/TextFonts/Conceptual/CocoaTextArchitecture/Introduction/Introduction.html#//apple_ref/doc/uid/TP40009459)

[`func addTextContainer(NSTextContainer)`](/documentation/UIKit/NSLayoutManager/addTextContainer(_:))

Appends the specified text container to the series of text containers where the layout manager arranges text.

  [Text System Storage Layer Overview](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/TextStorageLayer/TextStorageLayer.html#//apple_ref/doc/uid/10000087i)



---

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)