点击UITextFiled弹出UIDatePicker, 而不是键盘.

首先需要在View加载结束的时候指定文本的InputView

    UIDatePicker *datePicker = [[UIDatePicker alloc] init];
    datePicker.datePickerMode = UIDatePickerModeDate;
    [datePicker addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged];
    self.txtDate.inputView = datePicker;

然后需要指定当UIDatePicker变动的时候的事件是什么. 此处就是为了给文本框赋值.

- (IBAction)dateChanged:(id)sender
{
    UIDatePicker *picker = (UIDatePicker *)sender;
    self.txtDate.text = [NSString stringWithFormat:@"%@", picker.date];
 
}

然后当文本框编辑结束时, 需要让UIDatePicker消失.

- (IBAction)doneEditing:(id)sender
{
    [self.txtDate resignFirstResponder];
}

然后把文本框在IB中, 指向定义好的txtDate就行了~

你可能感兴趣的:(点击UITextFiled弹出UIDatePicker, 而不是键盘.)