A. Requirements1. Learn the basic configuration of DatePicker 2. Use TextField to summon the input keyboard view of the specified type, where DatePicker3 is used. Add a uitoolbar above the input keyboard to enable functions such as turning off the keyboardB.datepicker Use1.DatePicker Main Properties Mode: Displays the content, you can select the date, Free combination of time locale: Display language style interval: time interval for each option date: Current selected time constraint: Specify minimum and maximum time timer: Timer 2. Using code creation DatePicker (1) Drag into a TextField (2) to create DatePicker, and specify TextField input view is created DatePicker
1 //1. Create DatePicker2Uidatepicker *datepicker =[[Uidatepicker alloc] init];3 //2. Setting the Mode4 [DatePicker setdatepickermode:uidatepickermodedate];5 //3. Set Locale6[DatePicker Setlocale:[nslocale Localewithlocaleidentifier:@"ZH_CN"]];7 //4. Set the TextField response keyboard to DatePicker8[Self.textfield Setinputview:datepicker];
3.UIToolBar(1) The child element of the Uitoolbar can only be bar Button item, and the other element (2) Item style can be selected (3) as the item style for the interval flexible space can automatically fill the void in bar 4. Creating Uitoolbar with Code
1 //1. Create Uitoolbar2Uitoolbar *toolbar =[[Uitoolbar alloc] init];3 //Toolbar.backgroundcolor = [Uicolor graycolor];4 //Toolbar.tintcolor = [Uicolor bluecolor];5Toolbar.bartintcolor = [Uicolor Graycolor];//This is the background color of Uitoolbar.6Toolbar.frame = CGRectMake (0,0, the, -);//Size,uitoolbar must be set to display, otherwise only item can be displayed, and cannot be clicked7 //2. Create Item8Uibarbuttonitem *item1 = [[Uibarbuttonitem alloc] Initwithtitle:@"previous"Style:uibarbuttonitemstyleplain target:self Action: @selector (previousclicked)];9 TenUibarbuttonitem *item2 = [[Uibarbuttonitem alloc] Initwithtitle:@"Next"Style:uibarbuttonitemstyleplain target:self Action: @selector (nextclicked)]; One AUibarbuttonitem *item3 = [[Uibarbuttonitem alloc] Initwithtitle:@"Complete"Style:uibarbuttonitemstyleplain target:self Action: @selector (finishclicked)]; - - //Gap Item theUibarbuttonitem *spaceitem =[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemflexiblespace target:self action: NIL]; - - //3. Add Item to Uitoolbar -Toolbar.items =@[item1, item2, Spaceitem, item3]; + - //4. Add Uitoolbar to the top of the keyboard and set the secondary view to TextField +Self.textField.inputAccessoryView = ToolBar;
[iOS base Control-6.10.3] DatePicker & Uitoolbar