In this recipe, we will learn how to display simple text blocks with editing functionality.
In this recipe, we will discuss the usage of UITextView
and how to display editable text with it. Create a new iPhone Single View Application project in Xamarin Studio and name it TextViewApp
.
Perform the following steps:
Open
TextViewAppViewController.xib
in Interface Builder.Add a
UIButton
near the top of its view and aUITextView
below it. Connect both objects to their outlets.Save the document.
Back in Xamarin Studio, enter the following
ViewDidLoad
method in theTextViewAppViewController
class:public override void ViewDidLoad () { base.ViewDidLoad (); this.buttonFinished.Enabled = false; this.buttonFinished.TouchUpInside += (sender, e) => { this.myTextView.ResignFirstResponder(); } ; this.myTextView.Delegate = new MyTextViewDelegate(this); }
Add the following nested class:
private class MyTextViewDelegate : UITextViewDelegate...