Book Image

iOS Development with Xamarin Cookbook

By : Dimitrios Tavlikos (USD)
Book Image

iOS Development with Xamarin Cookbook

By: Dimitrios Tavlikos (USD)

Overview of this book

Table of Contents (22 chapters)
iOS Development with Xamarin Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Displaying and editing text


In this recipe, we will learn how to display simple text blocks with editing functionality.

Getting ready

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.

How to do it...

Perform the following steps:

  1. Open TextViewAppViewController.xib in Interface Builder.

  2. Add a UIButton near the top of its view and a UITextView below it. Connect both objects to their outlets.

  3. Save the document.

  4. Back in Xamarin Studio, enter the following ViewDidLoad method in the TextViewAppViewController 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);
    }
  5. Add the following nested class:

    private class MyTextViewDelegate : UITextViewDelegate...