Handling User Input
In Lesson 9 you were introduced to the
UILabel classes. The
UILabel class enables you to display static text on the screen. In this lesson, you learn to use text fields and text views to accept input from users. Text fields enable users to type a single line of text and are instances of the
UITextField class. Text views, on the other hand, enable users to type in multiple lines of text and are instances of the
UITextView class. Both classes are part of the UIKit framework.
To create a text field, simply drag and drop a Text Field object from the Object library onto a storyboard scene (see Figure 11.1).
You can use the Attribute inspector to set up several attributes of the text field, including the Placeholder, Alignment, Border Style, Text Color, Font, and the type of keyboard that is displayed when the user taps on the text field (see Figure 11.2).
A placeholder is some text that is displayed in the text field when it is empty, typically prompting the user to enter some information in the field. You can choose from seven different keyboards to associate with a text field; the choice you make will depend on the type of data you expect. These keyboard styles can be selected using the Attribute ...