iOS Guides | Samples

MonoTouch.UIKit.NSTextContainer Class

Models the geometric layout of a page in Text Kit.

See Also: NSTextContainer


[MonoTouch.Foundation.Register("NSTextContainer", true)]
[MonoTouch.ObjCRuntime.Introduced(MonoTouch.ObjCRuntime.PlatformName.iOS, 7, 0, MonoTouch.ObjCRuntime.PlatformArchitecture.None, null)]
public class NSTextContainer : NSObject, INSCoding, INSTextLayoutOrientationProvider, IDisposable


iOS 7 introduced "Text Kit," a broad set of APIs and modifications of existing classes, built on MonoTouch.CoreText, that greatly expands the typographical flexibility of iOS.

A NSLayoutManager maintains a list of one or more NSTextContainers in its NSLayoutManager.TextContainers property. The NSLayoutManager lays out the text through these NSTextContainers sequentially. Typically, each container will be handed to a UITextView which will be laid out on the display surface sequentially. For text to flow from one UITextView to another, the first UITextView's UITextView.ScrollEnabled property must be set to false.

The following example shows text laid out in a two-column format.

C# Example

var storage = new NSTextStorage();

var layoutManager = new NSLayoutManager();
//NSTextContainer defines a logical block (page, column)
var leftHandContainer = new NSTextContainer(size);

//Column 1
var leftHandView = new UITextView(new RectangleF(new PointF(padding, padding), new SizeF(UIScreen.MainScreen.Bounds.Width / 2 - padding * 2, UIScreen.MainScreen.Bounds.Height - padding * 2)), leftHandContainer);
leftHandView.BackgroundColor = UIColor.Green;
leftHandView.ScrollEnabled = false;

//Column 2
var rightHandContainer = new NSTextContainer(size);
var rightHandView = new UITextView(new RectangleF(new PointF(padding * 2 + size.Width, padding), size), rightHandContainer);
rightHandView.BackgroundColor = UIColor.Red;

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 UIView (TwoColumnView).

A NSTextContainer contains an array of zero or more UIBezierPath objects in its NSTextContainer.ExclusionPaths property. Text will not be placed within these paths.

Related content


Namespace: MonoTouch.UIKit
Assembly: monotouch (in monotouch.dll)
Assembly Versions:

The members of MonoTouch.UIKit.NSTextContainer are listed below.

See Also: NSObject

Public Constructors

Default constructor, initializes a new instance of this class.
A constructor that initializes the object from the data stored in the unarchiver object.
Constructor to call on derived classes to skip initialization and merely allocate the object.
Creates a new NSTextContainer with a bounding rectangle set to size.
A constructor used when creating managed representations of unmanaged objects; Called by the runtime.

Public Properties

ClassHandleIntPtr. The handle for this class.
ExclusionPathsUIBezierPath[]. An array of UIBezierPaths from which text will be excluded.
HeightTracksTextViewBoolean. Whether the NSTextContainer changes its NSTextContainer.Size as its associated UITextView is resized.
IsSimpleRectangularTextContainerBoolean. 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.
LayoutManagerNSLayoutManager. The NSLayoutManager controlling this NSTextContainer.
LayoutOrientationNSTextLayoutOrientation. The layout orientation of the text.
LineBreakModeUILineBreakMode. The behavior of the last line inside this NSTextContainer.
LineFragmentPaddingSingle. The amount, in points, by which text is inset within line fragment rectangles. Default is 5.0 points.
MaximumNumberOfLinesUInt32. The maximum number of lines that can be stored in the receiver.
SizeSizeF. The size of the NSTextContainer's bounding rectangle, regardless of the size of its region.
WidthTracksTextViewBoolean. Whether the NSTextContainer changes its NSTextContainer.Size as its associated UITextView is resized.

Public Methods

GetLineFragmentRect(RectangleF, UInt32, NSWritingDirection, out RectangleF) : RectangleF
The bounds of a line fragment rectangle inside this NSTextContainer for the proposed rectangle.
Replaces the current NSLayoutManager.

Protected Methods

Releases the resources used by the NSTextContainer object.