0

我有UIImage箭头标记,我有地方自定义按钮。当我单击此按钮时,我想显示日期选择器。从日期选择器中选择日期后,我需要将所选日期显示为按钮文本。我正在使用XIB的按钮。

4

2 回答 2

1

使用以下代码,

[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];
    }
于 2013-04-15T10:33:24.420 回答
1

您可以从关闭 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];
于 2013-04-15T10:34:35.870 回答