iosswiftxcodefscalendar

Allocate weekend day FSCalendar


I use FSCalendar.

How i can allocate weekend day? For example in red color is weekend, other days except weekends is blue. I means to allocate not day of the week (like a sunday, saturday), namely day, i.e. date:

Monday is 0 - blue color

Tuesday is 1 - blue color

...

Saturday is 5 - red color

Sunday is 6 - red color

Monday is 7 - blue color

...

Saturday is 12 - red color

Sunday is 13 - red color

and so on


Solution

  • Do the weekend / weekday calculation in your willDisplayCell method using this extension method for Date:

    extension Date {
      var isWeekend: Bool {
        return NSCalendar(calendarIdentifier: NSCalendar.Identifier.gregorian)!.isDateInWeekend(self)
      }
    }
    

    Depending on whether it is weekend or weekday, set your FSCalendarCell's following properties:

    cell?.eventIndicator.numberOfEvents = 1
    cell?.eventIndicator.isHidden = false
    cell?.eventIndicator.color = isWeekend ? UIColor.red : UIColor.blue