How to remove setMaximumDate for UIDatePicker in ios

UseriOSDev Source

I am using one UIDatePicker for two UITextfields in the same page.For one UITextfield I am setting the setMaximumDate and for the other UITextfield I don't want the maximum date.But still the other UITextfield is as well fetching the same setMaximumDate that is set for the first textfield. Is there any way to remove the already set setMaximumDate for the second textfield in UIDatePicker?



answered 2 weeks ago Krunal #1

Handle max date assignment in UITextFieldDelegate.


UIDatePicker * datePicker;
@property(nonatomic, strong) UITextField * textField1;
@property(nonatomic, strong) UITextField * textField2;

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {

    if (textField == self.textField1) {
        datePicker.maximumDate = [NSDate date];
    } else if (textField == self.textField2) {
        datePicker.maximumDate = nil;

    return true;


let datePicker = UIDatePicker()

let textField1 =  UITextField()
let textField2 = UITextField()

func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {

    if textField == textField1 {
        datePicker.maximumDate = Date()
    } else if textField == textField2 {
        datePicker.maximumDate = nil

    return true

comments powered by Disqus