iOS Learning Uidatepicker controls use

Source: Internet
Author: User

The control for selecting a time date on iOS is like this, the left side is a mix of time and date, and the right side is a simple date pattern.

,

You can choose the mode you want, time, date,date and time, Count down timer four mode.

This article briefly describes the use of the Pickerdate control

1. Create a new singe View application named Datepickdemo, other settings

2. Placing controls

Open the Viewcontroller.xib, drag a DatePicker control onto the interface, drag a button control to the interface, double-click the button, enter "Select DateTime"

3, the establishment of XIB and Viewcontroller Association

Press the Command+alt+enter key to open assistant Editor, select DatePicker to hold down the control key, drag to the ViewController.h,

Establish outlet DatePicker.

Create an action association map for the button in the same way, named Selectdate, with the event type default touch up Inside.

4. Implementation code

Click VIEWCONTROLLER.M to locate the

-(ibaction) Selectdate: (ID) sender {

}

Add a 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:@ " Determine "otherbuttontitles:nil, nil";
[Alert show];
}

Run to see the effect:

5, modify the mode into date mode, modify the code

[Dateformatter setdateformat:@"Yyyy-mm-dd"];

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

iOS Learning Uidatepicker controls use

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.