iosswiftxcodeswift5swiftui-datepicker

Setting only specific months in UIDatePicker Swift 5


In my project i want to apply condition like, user can select date only 3months from current date.

I.e i want to display a date picker containing Month and Day with range of 90 days.

Eg. November is going on so only, November December January should be displayed in Date picker for picking.

How can i achieve that??


Solution

  • You can try something like this:

    datePicker.maximumDate = Calendar.current.date(byAdding: .month, value: 3, to: Date())