In this recipe, we will learn how to use buttons to receive and respond to user input.
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.
Perform the following steps:
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); ...