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

Receiving user input with buttons


In this recipe, we will learn how to use buttons to receive and respond to user input.

Getting ready

We used buttons in Chapter 1, Development Tools, to discuss how to use Interface Builder to add controls to the user interface. In this recipe, we will describe the UIButton class in more detail. Open the FirstViewApp project, which we created in the previous recipe, in Xamarin Studio. Increase the height of the view, which we added, to cover the whole device screen in Interface Builder and save the document.

How to do it...

Perform the following steps:

  1. We will programmatically add a button in our interface. This button will change our view's background color when tapped. Open the FirstViewAppViewController.cs file and enter the following code in the class:

    UIButton buttonChangeColor;
    private void CreateButton ()
    {
      RectangleF viewFrame = this.subView.Frame;
      RectangleF buttonFrame = new RectangleF (10f, viewFrame.Bottom - 200f, viewFrame.Width - 20f, 50f);
    ...