NSTextContainer Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Models the geometric layout of a page in Text Kit.
[Foundation.Register("NSTextContainer", true)]
public class NSTextContainer : Foundation.NSObject, AppKit.INSTextLayoutOrientationProvider, Foundation.INSSecureCoding, IDisposable
[<Foundation.Register("NSTextContainer", true)>]
type NSTextContainer = class
inherit NSObject
interface INSCoding
interface INativeObject
interface IDisposable
interface INSSecureCoding
interface INSTextLayoutOrientationProvider
- Inheritance
- Attributes
- Implements
Remarks
iOS 7 introduced "Text Kit," a broad set of APIs and modifications of existing classes, built on CoreText, that greatly expands the typographical flexibility of iOS.
A NSLayoutManager maintains a list of one or more NSTextContainers in its TextContainers property. The NSLayoutManager lays out the text through these NSTextContainers sequentially. Typically, each container will be handed to a NSTextView which will be laid out on the display surface sequentially.
The following example shows text laid out in a two-column format.
var storage = new NSTextStorage();
storage.SetString(attributedString);
var layoutManager = new NSLayoutManager();
storage.AddLayoutManager(layoutManager);
//NSTextContainer defines a logical block (page, column)
var leftHandContainer = new NSTextContainer(size);
layoutManager.AddTextContainer(leftHandContainer);
//Column 1
var leftHandView = new UITextView(new CGRect(new CGPoint(padding, padding), new CGSize(UIScreen.MainScreen.Bounds.Width / 2 - padding * 2, UIScreen.MainScreen.Bounds.Height - padding * 2)), leftHandContainer);
leftHandView.BackgroundColor = UIColor.Green;
leftHandView.ScrollEnabled = false;
AddSubview(leftHandView);
//Column 2
var rightHandContainer = new NSTextContainer(size);
layoutManager.AddTextContainer(rightHandContainer);
var rightHandView = new UITextView(new CGRect(new CGPoint(padding * 2 + size.Width, padding), size), rightHandContainer);
rightHandView.BackgroundColor = UIColor.Red;
AddSubview(rightHandView);


The preceding diagram illustrates the objects directly involved in the two-column layout. The NSTextStorage is the responsibility of some external model class and the two-column user-interface is specified by a custom NSView (TwoColumnView).
A NSTextContainer contains an array of zero or more NSBezierPath objects in its ExclusionPaths property. Text will not be placed within these paths.
Constructors
| Name | Description |
|---|---|
| NSTextContainer() |
Creates a new NSTextContainer with default values. |
| NSTextContainer(CGSize) | |
| NSTextContainer(NativeHandle) |
A constructor used when creating managed representations of unmanaged objects. Called by the runtime. |
| NSTextContainer(NSCoder) |
A constructor that initializes the object from the data stored in the unarchiver object. |
| NSTextContainer(NSObjectFlag) |
Constructor to call on derived classes to skip initialization and merely allocate the object. |
Properties
| Name | Description |
|---|---|
| Class | (Inherited from NSObject) |
| ClassHandle |
The Objective-C class handle for this class. |
| ContainerSize | |
| DebugDescription | (Inherited from NSObject) |
| Description | (Inherited from NSObject) |
| ExclusionPaths |
An array of NSBezierPaths from which text will be excluded. |
| ExposedBindings | (Inherited from NSObject) |
| Handle |
Handle (pointer) to the unmanaged object representation. (Inherited from NSObject) |
| HeightTracksTextView |
Whether the NSTextContainer changes its Size as its associated NSTextView is resized. |
| IsDirectBinding | (Inherited from NSObject) |
| IsProxy | (Inherited from NSObject) |
| IsSimpleRectangularTextContainer |
Gets a Boolean value that tells whether the receiver's text container is a simply connected rectangular region that has the exact orientation of the text view. |
| LayoutManager | |
| LayoutOrientation | |
| LineBreakMode | |
| LineFragmentPadding |
The amount, in points, by which text is inset within line fragment rectangles. Default is 5.0 points. |
| MaximumNumberOfLines |
The maximum number of lines that can be stored in the receiver. |
| RetainCount | (Inherited from NSObject) |
| Self | (Inherited from NSObject) |
| Size | |
| Superclass | (Inherited from NSObject) |
| SuperHandle |
Handle used to represent the methods in the base class for this NSObject. (Inherited from NSObject) |
| TextLayoutManager | |
| TextView | |
| WidthTracksTextView |
Whether the NSTextContainer changes its Size as its associated NSTextView is resized. |
| Zone | (Inherited from NSObject) |