iOS 3.2 and Later
UIResponder has an inputView
property which can be used with UITextField and UITextView to replace the standard keyboard with any view you please, including a UIDatePicker. (See also: inputAccessoryView
, which can be used to put a toolbar above the keyboard.)
See Custom Views for Data Input in the iOS documentation for more details.
iOS 3.0 and Earlier
If you want the picker to pop up as the keyboard does, you have to do this yourself. It's not too hairy.
To make the picker view slide into position from the bottom of the screen:
pickerView.frame = <offscreen, just below the main view>
[UIView beginAnimations:@"PickerUp" context:nil];
pickerView.frame = <onscreen, at the bottom of the view>;
[UIView commitAnimations];
To make the picker view slide away when done:
[UIView beginAnimations:@"PickerDown" context:nil];
pickerView.frame = <offscreen, just below the main view>
[UIView commitAnimations];
The keyboard is handled automagically because it is managed by UITextView/UITextField; since you want a custom input view, you have to write the code to manage it yourself.
If you go this route, you should look read the documentation about becomeFirstResponder
and the whole UIResponder chain, so your custom control plays well with the system and other text fields.
If you want a toolbar above the picker, just create a generic UIView containing the toolbar, picker, and anything else you want to pop up from below. Then animate that container view in, instead of just the picker.