iOS Guides | Samples

MonoTouch.UIKit.NSTextContainer Class

Models the geometric layout of a page in Text Kit.

See Also: NSTextContainer

Syntax

[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

Remarks

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();
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 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;
AddSubview(leftHandView);

//Column 2
var rightHandContainer = new NSTextContainer(size);
layoutManager.AddTextContainer(rightHandContainer);
var rightHandView = new UITextView(new RectangleF(new PointF(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 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

Requirements

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

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

[read-only]
override
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.
[read-only]
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.
ReplaceLayoutManager(NSLayoutManager)
Replaces the current NSLayoutManager.

Protected Methods

override
Dispose(Boolean)
Releases the resources used by the NSTextContainer object.