The control for selecting a time date on iOS is like this, the left side is a mix of time and date, and the right side is a simple date pattern.
,
You can choose the mode you want, time, date,date and time, Count down timer four mode.
This article briefly describes the use of the Pickerdate control
1. Create a new singe View application named Datepickdemo, other settings
2. Placing controls
Open the Viewcontroller.xib, drag a DatePicker control onto the interface, drag a button control to the interface, double-click the button, enter "Select DateTime"
3, the establishment of XIB and Viewcontroller Association
Press the Command+alt+enter key to open assistant Editor, select DatePicker to hold down the control key, drag to the ViewController.h,
Establish outlet DatePicker.
Create an action association map for the button in the same way, named Selectdate, with the event type default touch up Inside.
4. Implementation code
Click VIEWCONTROLLER.M to locate the
-(ibaction) Selectdate: (ID) sender {
}
Add a response code here
-(Ibaction) Selectdate: (ID) Sender {
NSDate *select = [DatePicker Date];
NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
[Dateformatter setdateformat:@ "Yyyy-mm-dd hh:mm"];
NSString *dateandtime = [Dateformatter stringfromdate:select];
Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "Time Prompt" Message:dateandtime delegate:self cancelButtonTitle:@ " Determine "otherbuttontitles:nil, nil";
[Alert show];
}
Run to see the effect:
5, modify the mode into date mode, modify the code
[Dateformatter setdateformat:@"Yyyy-mm-dd"];
Example code: Https://github.com/schelling/YcDemo
iOS Learning Uidatepicker controls use