2

I'm trying the tutorial for JTAppleCalendar from the youtube. In this I'm making custom calendar in which under the date label I'm trying to show the current month name. I'm also getting the month name at the top of the view. When I pass the month name value it shows properly at the top of the view but when i pass to my label in a cell it just show label text not the month name. How can I get the month name there? My code for calendar is this:

func setUpViewForCalendar(from visibleDate: DateSegmentInfo){

    let date  = visibleDate.monthDates.first?.date
    self.formatter.dateFormat = "yyyy MM dd"
    self.yearLbl.text = self.formatter.string(from: date!)
    self.formatter.dateFormat = "MMMM"
    self.monthLbl.text = self.formatter.string(from: date!)
}
extension ViewController : JTAppleCalendarViewDataSource{
func calendar(_ calendar: JTAppleCalendarView, willDisplay cell: JTAppleCell, forItemAt date: Date, cellState: CellState, indexPath: IndexPath) {

}

func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {
    formatter.dateFormat = "yyyy MM dd"
    formatter.timeZone = Calendar.current.timeZone
    formatter.locale = Calendar.current.locale

    let startDate = formatter.date(from: "2018 01 01")
    let endDate = formatter.date(from: "2018 12 31")

    let parameter = ConfigurationParameters(startDate: startDate!, endDate: endDate!)
    return parameter
}

}

extension ViewController : JTAppleCalendarViewDelegate{

func calendar(_ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell {
    let cell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: "customCell", for: indexPath) as! CustomCell
    cell.dateLbl.text = cellState.text
    cell.monthLbl.text = self.monthLbl.text
    print(cell.monthLbl.text)
    handleCellTextColor(view: cell, cellState: cellState)
    return cell
}

func calendar(_ calendar: JTAppleCalendarView, didSelectDate date: Date, cell: JTAppleCell?, cellState: CellState) {
    handleCellTextColor(view: cell!, cellState: cellState)
}

func calendar(_ calendar: JTAppleCalendarView, didDeselectDate date: Date, cell: JTAppleCell?, cellState: CellState) {
    handleCellTextColor(view: cell!, cellState: cellState)
}

func calendar(_ calendar: JTAppleCalendarView, didScrollToDateSegmentWith visibleDates: DateSegmentInfo) {
    setUpViewForCalendar(from: visibleDates)
}

}

This is how my calendar looks like, enter image description here

Enea Dume
  • 3,014
  • 3
  • 21
  • 36
raheem
  • 689
  • 2
  • 8
  • 16

1 Answers1

0
let formatter = DateFormatter()
formatter.dateFormat = "MMMM"

func calendar(_ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell {
    let cell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: "customCell", for: indexPath) as! CustomCell
    cell.dateLbl.text = cellState.text
    cell.monthLbl.text = formatter.string(from: date)
    print(cell.monthLbl.text)
    handleCellTextColor(view: cell, cellState: cellState)
    return cell
}
Just a coder
  • 15,480
  • 16
  • 85
  • 138