Chapter 10

Date Pickers

In the previous lesson you learned about picker views. Although it is possible to create a picker view with several components to allow your user to enter a date, Apple provides a special user interface component for precisely this purpose. The date picker is a special picker that can be used to select dates and times. You can configure it to display only date, only time, or both date and time as shown in Figure 10-1.

The UIDatePicker class provides the functionality of a date picker, which is part of the UIKit framework. The UIDatePicker class privately uses a UIPickerView instance, but you cannot access this instance directly.

A date picker is much simpler to use than a picker view. For starters, it does not require you to provide a delegate or data source object. Creating a date picker is a simple matter of dragging the Date Picker component from the Object library onto a scene in your storyboard (Figure 10-2) and then creating an appropriate outlet in your view controller class using the assistant editor.

The mode of the date picker refers to whether it displays date, time, or both date and time. You can also specify the range of values that should be displayed by the date picker. Both these tasks can be accomplished by using the assistant editor (Figure 10-3).

You can read the date currently selected in ...

Get iPhone and iPad App 24-Hour Trainer now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.