get previous month
jeremieIOS opened this issue · comments
Hi,
thank you very much for your work. Can you tell me how can I configure the calendar as such :
It starts on the current month and it can only go for previous month
How can go to X previous months ? I edit the field CalendarPopup.startDate but it doesn't work.
Thank you for your help
Hi, You can set start month like this:
in function showCalendar()
let formatter = DateFormatter()
formatter.dateFormat = "yyyy/MM/dd HH:mm"
let startDate = formatter.date(from: "2016/10/01 00:00")
xibView.startDate = startDate!
Thank you very much for answering me :) I've tried what you told me but it doesn't do what I want.
I'll try to be clearer.
I'm creating a app that allow you to report your real activity. So you can't report or use a calendar of futur month. So I would like to know how can the calendar start in the current month but allow me to go to previous month , at least for 1 year in the past, if I want to. Do you understand ?
"xibView.startDate" - it means minimum date
"Calendar.current.date(byAdding: .month, value: -12, to: currentDate)!" - minus 12 month from current date
maximum date you can set inside CalendarPopUp.swift function awakeFromNib():
"endDate = Calendar.current.date(byAdding: .month, value: 2, to: startDate)!" - endDate == maximum
@IBAction func showCalendar(_ sender: UIButton) {
let xibView = Bundle.main.loadNibNamed("CalendarPopUp", owner: nil, options: nil)?[0] as! CalendarPopUp
xibView.calendarDelegate = self
xibView.selected = currentDate
xibView.startDate = Calendar.current.date(byAdding: .month, value: -12, to: currentDate)!
PopupContainer.generatePopupWithView(xibView).show()
}
Setting startDate and endDate in showCalendar method doesn't work, it changes nothing. Calendar starts from current month, and ends after 2 months how was set in CalendarPopUp class. How to fix that? Thanks.