DatePicker Custom--IOS

Source: Internet
Author: User

/** * Create a time picker*/- (void) Createpickerview {self.datepicker=[[Uidatepicker alloc] init]; _datepicker.backgroundcolor=[Uicolor Whitecolor]; //set to display only Chinese[_datepicker Setlocale:[nslocale Localewithlocaleidentifier:@"ZH-CN"]]; //Set display date only_datepicker.datepickermode =uidatepickermodedate; //Call the time picker when the cursor moves to a text boxSelf.birthTextField.inputView =_datepicker; //Create a tool barUitoolbar *toolbar =[[Uitoolbar alloc] init];
Setting the background color Toolbar.bartintcolor
=[Uicolor Whitecolor]; Toolbar.frame= CGRectMake (0,0, Screen_width, -); //Add a button to a toolbarUibarbuttonitem *cancleitem = [[Uibarbuttonitem alloc] Initwithtitle:@"Cancel"Style:uibarbuttonitemstyleplain target:self Action: @selector (cancel)]; Uibarbuttonitem*spaceitem =[[Uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemfixedspace target:self Action:nil]; //set the width of the uibarbuttonsystemitemfixedspaceSpaceitem.width = Screen_width- -; Uibarbuttonitem*sureitem = [[Uibarbuttonitem alloc] Initwithtitle:@"Confirm"Style:uibarbuttonitemstyleplain target:self Action: @selector (sure)];
Set Font Color Toolbar.tintcolor
=[Uicolor Redcolor]; Toolbar.items=@[cancleitem, Spaceitem, Sureitem]; //set the secondary view of the text input box keyboardSelf.birthTextField.inputAccessoryView =ToolBar;}/** * Click the Cancel button * * @param datePicker*/- (void) Cancel {}/** * Click OK button * * @param datePicker*/- (void) sure {nsstring*date = [NSString stringWithFormat:@"%@", _datepicker.date]; NSString*birth = [Date Substringtoindex:Ten]; Self.birthTextField.text=birth; [_birthtextfield Resignfirstresponder];}

The effect is as follows:

DatePicker Custom--IOS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.