Issue related to textfield and datepicker

后端 未结 1 657
臣服心动
臣服心动 2021-01-25 00:52

I have an issue related to hide and show the datepicker view when click on textfield...Actually I have 2 textfields..Here is my problem image...

Problem

相关标签:
1条回答
  • 2021-01-25 01:39

    Batter to use date picker as input view

    UIView *viewDateInput = [[UIView alloc] initWithFrame:CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width, 200)];
    [viewDateInput setBackgroundColor:[UIColor whiteColor]];
    self.pickerDate = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0, viewDateInput.frame.size.width, viewDateInput.frame.size.height)];
    self.pickerDate.datePickerMode = UIDatePickerModeDate;
    [viewDateInput addSubview:self.pickerDate];
    [self.pickerDate addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged];
    [self.txtDate setInputView:viewDateInput];
    

    Function For date Change

    - (void)dateChanged:(id)sender
    {
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM-dd"];
        NSString *currentTime = [dateFormatter stringFromDate:self.pickerDate.date];
    self.txtDate.text = currentTime;
    }
    
    0 讨论(0)
提交回复
热议问题