0

I have an array of object contains bookings

class MonthBookings: NSObject {

    var date: Date = Date()    
    var bookings_count: Int = 0
}

var bookings = [MonthBookings]()

So I need to check if cell date is equal to some date in bookings array then change cell color for this date in cell.

I have tried this way down below but didn't work:

func calendar(_ calendar: JTAppleCalendarView, willDisplayCell cell: JTAppleDayCellView, date: Date, cellState: CellState) {
    guard let sfbCell = cell as? SFBCalendarCell else {return}

    let booking = self.bookingsMonths[cellState.row()]

    if booking.date == date {
        sfbCell.dayText.textColor = .red
    } else {
        sfbCell.dayText.textColor = .black
    }
}
Anh Pham
  • 2,108
  • 9
  • 18
  • 29
Ahmed R.
  • 1,209
  • 1
  • 12
  • 22

2 Answers2

0

Are you doing a day compared or the actual date/Time? Try something like this.

let order = CalendarManager.currentCalendar.compare(cellState.date, to: 
Date(), toGranularity: .day)
  if order == .orderedSame {
    calendarCell.dayNumberLabel.textColor = UIColor.white
  }
zsteed
  • 97
  • 2
  • 6
  • In my case I want to show different colour for 90 consecutive dates from my custom, Could you please tell how to achieve that ? – Vignesh Mar 12 '19 at 10:08
0

I Solved by using Contains method

if bookingsMonths.contains(where: { $0.date == cellState.date && $0.bookings_count != 0 }) {

      sfbCell.dayText.font = UIFont.boldSystemFont(ofSize: 15)

} else {

      sfbCell.dayText.font = UIFont.systemFont(ofSize: 15)

}
Ahmed R.
  • 1,209
  • 1
  • 12
  • 22