Swift-Usage of the Date selection control (Uidatepicker) basics

Source: Internet
Author: User

Pure code Creation Date Selection Control 1 2 3 4 5 6 7 8 9 (import  Uikit   CL-K-A-day) ass  Viewcontroller:  uiviewcontroller  {       override  func  Viewdidload () {         super. Viewdidload ()                    //create date selector           let  datepicker =  uidatepicker (frame:  cgrectmake (0.0, 0.0, 320.0, 216.0)         //Set the date selector area to Chinese, the selector date is displayed as Chinese           datepicker.locale =  Nslocale (localeidentifier:  "ZH_CN")          /Note: The method name in the action needs to be preceded by a colon ":"          Datepicker.addtarget (self, action:  "datechanged:",              forcontrolevents:  uicontrolevents. valuechanged)          self. View.addsubview (DatePicker)      }           //Date Selector Response Method      func   datechanged (DatePicker:  uidatepicker) {        //Update Reminder time text box          let  Formatter =  nsdateformatter ()          //Date style          Formatter.dateformat =   "yyyy mm month DD Day HH:MM:SS"          print (Formatter.stringfromdate ( datepicker.date)     }        override  func  Didreceivememorywarning () {         super. didreceivememorywarning ()     }}
3, date selection control text changed to Chinese
The text in the default date selection control is in English, and if you want to display Chinese, you need to set the area of the date selection control as follows setting 1 2//Setting the date selector area to Chinese, the selector date is displayed as Chinese Datepicker.locale = Nslocale ( Localeidentifier: "ZH_CN")
Related Article

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.

Tags Index: