Main properties of DatePicker:
- Mode: Displays the content, can choose the date, the time free combination
- Locale: the displayed language style
- Interval: Time interval for each option
- Date: The currently selected time
- Constraint: Specify minimum and maximum time
- Timer: Timer
Creating DatePicker with Code
// 1. Create DatePicker Uidatepicker *datepicker = [[Uidatepicker alloc] init]; // 2. Setting the Mode [DatePicker setdatepickermode:uidatepickermodedate]; // 3. Set Locale [DatePicker setlocale:[nslocale Localewithlocaleidentifier:@ "zh_cn"]; // 4. Set the TextField response keyboard to DatePicker [Self.textfield Setinputview:datepicker];
Creating Uitoolbar with Code
//1. Create UitoolbarUitoolbar *toolbar =[[Uitoolbar alloc] init];Toolbar.bartintcolor = [Uicolor Graycolor];//This is the background color of Uitoolbar.Toolbar.frame = CGRectMake (0,0, the, -);//Size,uitoolbar must be set to display, otherwise only item can be displayed, and cannot be clicked//2. Create ItemUibarbuttonitem *item1 = [[Uibarbuttonitem alloc] Initwithtitle:@"previous"Style:uibarbuttonitemstyleplain target:self Action: @selector (previousclicked)]; Uibarbuttonitem*ITEM2 = [[Uibarbuttonitem alloc] Initwithtitle:@"Next"Style:uibarbuttonitemstyleplain target:self Action: @selector (nextclicked)]; Uibarbuttonitem*ITEM3 = [[Uibarbuttonitem alloc] Initwithtitle:@"Complete"Style:uibarbuttonitemstyleplain target:self Action: @selector (finishclicked)]; //Gap ItemUibarbuttonitem *spaceitem =[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemflexiblespace target:self action:nil ]; //3. Add Item to UitoolbarToolbar.items =@[item1, item2, Spaceitem, Item3]; //4. Add Uitoolbar to the top of the keyboard and set the secondary view to TextFieldSelf.textField.inputAccessoryView = ToolBar;
IOS UI Basics -14.0 DatePicker