Limiting UIDatePicker dates from a particular time. Such as Input DOB to a restricted age limit

后端 未结 2 1343
傲寒
傲寒 2020-11-28 13:36

In my code, I have a UITextField that when the user taps on opens a UIDatePicker to enable the user to easily and efficiently scroll through to their Date Of Birth. Obviousl

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 14:23

    UIDatePicker has a maximumDate that you can set. Simply set the mode to "Date" in IB and add: datePicker.maximumDate = NSDate(timeIntervalSinceNow: -504911232)

    -504911232 means 16 before today(accounting leap years)

提交回复
热议问题