uitextfield - Change the format of datepicker -
how can alter format of date yy/mm/dd
?
here have far:
- (void)textfielddidbeginediting:(uitextfield *)textfield { if (textfield == _celebration) { uidatepicker *datepicker = [[uidatepicker alloc]init]; [datepicker setdate:[nsdate date]]; [datepicker addtarget:self action:@selector(updatetextfield:) forcontrolevents:uicontroleventvaluechanged]; [self.celebration setinputview:datepicker]; } } - (void)updatetextfield:(id)sender { uidatepicker *picker = (uidatepicker*)self.celebration.inputview; self.celebration.text = [nsstring stringwithformat:@"%@",picker.date]; }
make formatter this
nsdateformatter* format = [[nsdateformatter alloc]init]; [format setdateformat:@"yy/mm/dd"];
get formatted string nsdate this
nsstring* testdate = [format stringfromdate:[nsdate date]];
get nsdate string so.
nsdate* reformdate = [format datefromstring:testdate];
release if not in arc, otherwise set nil [format release]; or format = nil;
you modify function this. set formatted date string uitextfield's text.
- (void)updatetextfield:(id)sender { uidatepicker *picker = (uidatepicker*)self.celebration.inputview; nsdateformatter* format = [[nsdateformatter alloc]init]; [format setdateformat:@"yy/mm/dd"]; nsstring* formatteddate = [format stringfromdate:picker.date]; self.celebration.text = formatteddate; format = nil; }
that beingness said uidatepicker doesn't back upwards formatting this. can reference class here. uidatepicker class reference
if set on format datepicker have build custom one. however, discourage since built in uidatepicker takes user's locale , language consideration automatically while format lock preferred format (which isn't right user depending on in world).
datepicker uitextfield
No comments:
Post a Comment