Use of the UIDatePicker Control for iOS Learning

Source: Internet
Author: User

On iOS, the time and date Selection control is like this. On the left side is the combination of time and date, and on the right side is the pure date mode.

,

You can select four modes as needed: Time, Date, Date and Time, and Count Down Timer.

 

 

This article briefly introduces the use of the PickerDate Control

 

 

1. Create a Singe View Application named DatePickDemo. Other settings

 

2. place controls

Open ViewController. xib, drag a DatePicker control to the interface, drag a Button control to the interface, double-click the Button, and enter "select Date and Time"

3. Establish an association between xib and ViewController

Press command + alt + enter to open the Assistant Editor, select DatePicker, press and hold the Control key, and drag it to viewController. h,

Create an Outlet datePicker.

Create an Action Association ing for the Button in the same way and name it selectDate. The event type is the default Touch Up Inside.

4. Implementation Code

 

Click ViewController. m and find

 

-(IBAction) selectDate :( id) sender {

}

Add response code here

 

-(IBAction) selectDate :( id) sender {NSDate * select = [datePicker date]; NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat: @ "yyyy-MM-dd HH: mm"]; NSString * dateAndTime = [dateFormatter stringFromDate: select]; UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "time prompt" message: dateAndTime delegate: self cancelButtonTitle: @ "OK" otherButtonTitles: nil, nil]; [alert show];}

Running results:

 

 

5. modify the code in Date mode.

 

    [dateFormatter setDateFormat:@"yyyy-MM-dd"];

 

Example code: https://github.com/schelling/YcDemo

Copyright Disclaimer: This article will be published at http://blog.csdn.net/totogo2010/, and you will be welcomed to enjoy the transfer and sharing. Please respect the work of the author. Keep this note and the author's blog link when reprinting. Thank you.

 

 

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.

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.