0

I am working on calendar implementation.

I want current and past dates to be selectable, but not future dates, as my application only requires current and past dates.

How do I disable the selection of future dates in a calendar?

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
Ashu Designer
  • 178
  • 1
  • 2
  • 10

1 Answers1

2

When a date is selected the JTAppleCalender view's delegate method didSelectDate will be getting called.

So you could handle your date selection inside this method like,

 func calendar(_ calendar: JTAppleCalendarView, didSelectDate date: Date, cell: JTAppleCell?, cellState: CellState) {
        if date == currentDate || date == previousDate {
           //do your logic here
        }
        else {
          return
        }
    }
Aravind A R
  • 2,674
  • 1
  • 15
  • 25
  • How to remove 3 months limit? – Ashu Designer Sep 07 '17 at 05:19
  • Also i want disable future date. – Ashu Designer Sep 07 '17 at 05:20
  • @AshuDesigner In JTAppleCalendarViewDelegate's `configureCalendar` function you can set the `ConfigurationParameters` where you can configure the start and end date – Aravind A R Sep 07 '17 at 06:21
  • @Arvind A R Thank You – Ashu Designer Sep 07 '17 at 09:00
  • Yes it is working fine but i have one more issue. I am working On JTAppleCalendar library, I have Set calendar on Both textboxes like FROM - TO Search. I want,like example FROM textbox have selected 3 january 2017 and second calander textbox have should be enable only 3 january -2017 to 7 sep 2017 current date – Ashu Designer Sep 07 '17 at 09:17
  • @AshuDesigner if its working fine it would be great if you could accept the answer so that it will be helpful to others too. – Aravind A R Sep 07 '17 at 09:19
  • var components = DateComponents() components.year = -100 let minDate = Calendar.current.date(byAdding: components, to: Date()) components.year = 100 let maxDate = Calendar.current.date(byAdding: components, to: Date()) – Ashu Designer Sep 08 '17 at 07:10