UIKit.NSTextContainer Class
Models the geometric layout of a page in Text Kit.

See Also: NSTextContainer Members


[Foundation.Register("NSTextContainer", true)]
public class NSTextContainer : Foundation.NSObject, Foundation.INSCoding, INSTextLayoutOrientationProvider, IDisposable


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 UIKit.NSLayoutManager maintains a list of one or more UIKit.NSTextContainers in its NSLayoutManager.TextContainers property. The UIKit.NSLayoutManager lays out the text through these UIKit.NSTextContainers sequentially. Typically, each container will be handed to a UIKit.UITextView which will be laid out on the display surface sequentially. For text to flow from one UIKit.UITextView to another, the first UIKit.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 UIKit.NSTextStorage is the responsibility of some external model class and the two-column user-interface is specified by a custom UIKit.UIView (TwoColumnView).

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

Related content


Namespace: UIKit
Assembly: Xamarin.iOS (in Xamarin.iOS.dll)
Assembly Versions: