Chapter 5. Capturing users’ actions: adding buttons
This chapter covers
- Creating an app with a button
- Buttons and how to use them
- Changing labels
You’re going to create another app in this chapter. This one will have a button the user can tap. Buttons are used throughout iPhone and iPad apps to allow the user to do some kind of action, such as make a phone call. Each number on the phone number screen is a button, for example, and the call and hang-up buttons are buttons too.
In this chapter you’ll add a label and a button to the app and write some code. The code you write will make the button change what the label displays. You’re also going to change how the label looks by implementing cosmetic changes.
Looking at the code
You can download all the projects from this book at www.manning.com/books/anyone-can-create-an-app or https://github.com/wlwise/AnyoneCanCreateAnApp, and you can refer to them anytime.
As usual, we’re going to start with pseudocode steps so that we follow a logical road map for completing this project. Here are the steps:
- Start a new project using the Single View Application template.
- Add a button and label to the storyboard, and run the app to test it.
- Connect the button and the label to the code (wire them up), and run the app to test it.
- Add code to change the text on the label when the button is clicked, and run the app to test it.
- Change how the label looks, and run the app to test it.