Minimum and maximum date in UIDatePicker

前端 未结 11 1278
不知归路
不知归路 2020-11-30 00:34

I want to get the minimum and maximum date from a date picker, but minimum date should be \"- 18\" of the current date and the maximum date should be \"- 100\" of current da

11条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-30 00:57

    Look at this for Swift version. User negative value (-) to subtract and positive value to add date component.

    1. Set minimum date

     yourDatePicker.minimumDate = Calendar.current.date(byAdding: .year, value: -1, to: Date())
    

    2. Set maximum date

     yourDatePicker.maximumDate = Calendar.current.date(byAdding: .year, value: 1, to: Date())
    

提交回复
热议问题