public override void ViewDidLoad () { base.ViewDidLoad (); textStorage = new InteractiveTextColoringTextStorage (); CGRect newTextViewRect = View.Bounds; newTextViewRect.X += 8; newTextViewRect.Width -= 16; var layoutManager = new NSLayoutManager (); var container = new NSTextContainer (new CGSize (newTextViewRect.Size.Width, float.MaxValue)); container.WidthTracksTextView = true; layoutManager.AddTextContainer (container); textStorage.AddLayoutManager (layoutManager); var newTextView = new UITextView (newTextViewRect, container); newTextView.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth; newTextView.ScrollEnabled = true; newTextView.KeyboardDismissMode = UIScrollViewKeyboardDismissMode.OnDrag; View.Add (newTextView); var tokens = new Dictionary<string, NSDictionary> (); tokens.Add ("Alice", new NSDictionary (UIStringAttributeKey.ForegroundColor, UIColor.Red)); tokens.Add ("Rabbit", new NSDictionary (UIStringAttributeKey.ForegroundColor, UIColor.Orange)); tokens.Add ("DefaultTokenName", new NSDictionary (UIStringAttributeKey.ForegroundColor, UIColor.Black)); textStorage.Tokens = tokens; SetText (); }
public override void ViewDidLoad() { base.ViewDidLoad(); textStorage = new InteractiveTextColoringTextStorage(); CGRect newTextViewRect = View.Bounds; newTextViewRect.X += 8; newTextViewRect.Width -= 16; var layoutManager = new NSLayoutManager(); var container = new NSTextContainer(new CGSize(newTextViewRect.Size.Width, float.MaxValue)); container.WidthTracksTextView = true; layoutManager.AddTextContainer(container); textStorage.AddLayoutManager(layoutManager); var newTextView = new UITextView(newTextViewRect, container); newTextView.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth; newTextView.ScrollEnabled = true; newTextView.KeyboardDismissMode = UIScrollViewKeyboardDismissMode.OnDrag; View.Add(newTextView); var tokens = new Dictionary <string, NSDictionary> (); tokens.Add("Alice", new NSDictionary(UIStringAttributeKey.ForegroundColor, UIColor.Red)); tokens.Add("Rabbit", new NSDictionary(UIStringAttributeKey.ForegroundColor, UIColor.Orange)); tokens.Add("DefaultTokenName", new NSDictionary(UIStringAttributeKey.ForegroundColor, UIColor.Black)); textStorage.Tokens = tokens; SetText(); }