iOS Development-datepicker Controls

Source: Internet
Author: User

The time control, whether Android or iOS, is a control that is bound to exist, with the exact same effect, showing the date, time, and four ways in which iOS can be selected, when, date,date and times, Count down Timer,demo is easier, You need a DatePicker control and a button to display the time or date, as follows:

Page Layout

Main.storyboard layout:

Y

Effect:

Code implementation

First drag the control into ViewController.h and drag the button's click into the VIEWCONTROLLER.M:

-(Ibaction) Showdate: (ID) Sender {    //Date selection time    nsdate *currentdate  = [_currentdatepicker date];    NSDateFormatter *myformatter = [[NSDateFormatter alloc] init];    Date format displayed//    [MyFormatter setdateformat:@ "Yy-mm-dd HH:mm:ss"];    [MyFormatter setdateformat:@ "yyyy mm month DD Day"];    NSString *time = [MyFormatter stringfromdate:currentdate];    Uialertview *alterview=[[uialertview alloc] initwithtitle:@ "Current Time" Message:time delegate:self cancelButtonTitle:@ "OK" Otherbuttontitles:nil, nil];    [Alterview show];}

The final effect is as follows:

DatePicker mode I choose is the time pattern, we can choose according to their own choice, the default is displayed in English, if DatePicker need to switch between English and Chinese, you can choose the locale to choose English:

iOS Development-datepicker Controls

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.