Disable Past Date in UIDatePicker in IPhone Objective C

前端 未结 3 454
春和景丽
春和景丽 2021-02-05 00:29

I am new to Objective C and IPhone development.

I am using a UIDatePicker in my IPhone Application and my requirement is to allow the user to choose the future date only

相关标签:
3条回答
  • 2021-02-05 00:38

    Use the following line,to disable the previous dates of an UIDatePicker.

    [picker setMinimumDate: [NSDate date]];
    

    The current date is displayed as shown below

    enter image description here

    0 讨论(0)
  • 2021-02-05 00:40

    For Swift :

    let todaysDate = Date()
    
    datePicker.minimumDate = todaysDate
    

    It will not let the user to pick a date older than Today

    OR

    Or, if you want to reduce the code, use following way:

    datePicker.minimumDate = Date()
    
    0 讨论(0)
  • 2021-02-05 00:57

    Did you try this

    [picker setMinimumDate: [NSDate date]];
    
    0 讨论(0)
提交回复
热议问题