Swift
Swift

Reputation: 1182

How to show previous, current and future months in JTAppleCalendar in Swift

for calendar i am using JTAppleCalendar in project,

here if i give startDate and endDate like below then i am getting initially current month

 extension ViewController: JTAppleCalendarViewDataSource {
func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {
    let formatter = DateFormatter()
    formatter.dateFormat = "yyyy MM dd"
    let startDate =  Date()
    let endDate = formatter.date(from: "2050 01 01")!
    return ConfigurationParameters(startDate: startDate, endDate: endDate)
}
}

with the above code i am able to show current and future months in calendar.. but i want to show initially current month and if i scroll left i need to show previous months and if i scroll right then need to show future months, but with the above code i am only able to scroll upto current month.. but i need to show its previous months as well, how to do that please do help

Upvotes: 0

Views: 530

Answers (1)

Victor Morei
Victor Morei

Reputation: 199

You must return your real startDate instead of Date() and then scroll to current month.

func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {
     let formatter = DateFormatter()
     formatter.dateFormat = "yyyy MM dd"
     let startDate =  formatter.date(from: "2010 01 01")!
     let endDate = formatter.date(from: "2050 01 01")!
     return ConfigurationParameters(startDate: startDate, endDate: endDate)
 }

then in your viewDidLoad you should call:

collectionView.scrollToDate(Date())

Upvotes: 2

Related Questions