JTAppleCalendar iOS get month in header to scroll it with calendar

1.1k views Asked by At
func calendar(_ calendar: JTAppleCalendarView, headerViewForDateRange range: (start: Date, end: Date), at indexPath: IndexPath) -> JTAppleCollectionReusableView {
        let header = calendar.dequeueReusableJTAppleSupplementaryView(withReuseIdentifier: "calendarHeader", for: indexPath) as!CalendarHeader
        header.monthLabel.text = monthName
        return header
    }

I want to get the month name here to display it in Header so that month name can scroll with the calendar vertically. How should I get it? Thank you for helping me

1

There are 1 answers

0
ayon.gupta On BEST ANSWER
let currentCalendar = Calendar.current

var monthFormatter = DateFormatter()


func calendar(_ calendar: JTAppleCalendarView, 
headerViewForDateRange 
range: (start: Date, end: Date), 
at indexPath: IndexPath) -> JTAppleCollectionReusableView {


      let date = range.start
      let month = calendarCurrent.component(.month, from: date)
      var monthName = monthFormatter.monthSymbols[month - 1]
        let header = calendar.dequeueReusableJTAppleSupplementaryView(withReuseIdentifier: "calendarHeader", for: indexPath) as!CalendarHeader
        header.monthLabel.text = monthName
        return header

    }

Hope you have found the solution to your problem. Thanks