I'm having UIImage
with arrow mark,on that I had place custom button.
When i clicked this button I want to Show te date picker.
After selecting the date from date-picker,I need to show selected date as button text.
I'm using the button by XIB.
Asked
Active
Viewed 1,046 times
0
-
Go through this [Datepicker and Button][1] [1]: http://stackoverflow.com/questions/12177261/how-to-show-selected-date-on-button-using-datepicker – lreddy Apr 15 '13 at 10:35
2 Answers
1
Use following code ,
[self.DatePicker addTarget:self
action:@selector(SetDatePickerTime:)
forControlEvents:UIControlEventValueChanged];
-(void)SetDatePickerTime:(id)sender
{
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"dd/MM/yyy"];
NSString *title = [outputFormatter stringFromDate:self.DatePicker.date];
NSLog(@"%@",[outputFormatter stringFromDate:self.DatePicker.date]);
[yourButton setTitle:title forState:UIControlStateNormal];
}

iPatel
- 46,010
- 16
- 115
- 137
1
You can do something like this from the method you dismiss the datePicker
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"MM/dd/yyyy hh:mm:ss a"];
NSString *dateString = [dateFormatter stringFromDate:[self.datePicker date]];
[self.dateButton setTitle:dateString forState:UIControlStateNormal];

Anupdas
- 10,211
- 2
- 35
- 60