Ios--uidatepicker How to use time picker details

Source: Internet
Author: User

Ios--uidatepicker How to use time picker details
There are four kinds of main types://date display,

Date and time display,


Time Display,


Countdown options


Common methods for Uidatepicker controls time selection controls

Uidatepicker *onedatepicker = [[Uidatepicker alloc] init];

Onedatepicker.frame = CGRectMake (0, 10, 320, 300); Set the location and size of the display

Onedatepicker.date = [NSDate Date]; Set the initial time

[Onedatepicker setdate:[nsdate datewithtimeintervalsincenow:48 *] animated:yes]; Set the time, have animation effect

Onedatepicker.timezone = [Nstimezone timezonewithname:@ "gtm+8"]; Set time zone, China in East eight district

Onedatepicker.minimumdate = [NSDate datewithtimeintervalsincenow:72 * 60 * 60*-1]; Set minimum time

Onedatepicker.maximumdate = [NSDate datewithtimeintervalsincenow:72 * 60 * 60]; Set maximum time

Onedatepicker.datepickermode = Uidatepickermodedateandtime; Set style

The following are all styles

typedef ns_enum (Nsinteger, Uidatepickermode) {

Uidatepickermodetime,//Show Time only

Uidatepickermodedate,//display date only

Uidatepickermodedateandtime,//display date and time

Uidatepickermodecountdowntimer//Display only hour and minute countdown timers

// };

[Onedatepicker addtarget:self Action: @selector (onedatepickervaluechanged:) forControlEvents: Uicontroleventvaluechanged]; Add Listener

[Self.view Addsubview:onedatepicker]; Add to view

[Onedatepicker release], onedatepicker = nil; Freeing memory

#pragma mark-Implements the Onedatepicker monitoring method

-(void) onedatepickervaluechanged: (Uidatepicker *) Sender {

NSDate *select = [Sender Date]; Gets the time that was selected

NSDateFormatter *selectdateformatter = [[NSDateFormatter alloc] init];

Selectdateformatter.dateformat = @ "Yy:MM:dd HH:mm:ss"; Format the time and date

NSString *dateandtime = [Selectdateformatter stringfromdate:select]; Convert the date type to a formatted string type

Show it through Uialertview.

Uialertview *alertview = [[Uialertview alloc] initwithtitle:@ "Time Tip" Message:dateandtime delegate:select cancelbuttontitle:@ "Cancle" otherbuttontitles:nil, nil];

[Alertview show];

[Alertview release], Alertview = nil;

[Selectdateformatter release], selectdateformatter = nil;

Print messages on the console

NSLog (@ "%@", [Sender Date]);

}

Ios--uidatepicker How to use time picker details

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.