How to display the date in circle having event using FSCalendar?

Viewed 947

I have programatically added FSCalendar using swift and getting the list of events from the api call. A s default the events is displaying like dot below the event date. But I need to display the event in the circle instead of the dot below the date.I tried many ways but it did not work.Is there any way to do it?

 func calendar(_ calendar: FSCalendar, numberOfEventsFor date: Date) -> Int {
   return Events[date.GetFormatedDateAsString(format: "dd.MM.YYYY")] ?? 0
 }
1 Answers

First you have to define the DataSource and Delegate for FSCalendar.

For example, i have a Date array for my calendar:

var eventsDateArray: [Date] = [SomeDatesExample]

So, I use FSCalendarDelegateAppearance to change the appearance of the cell, when my date is rendered, using the methods titleDefaultColorFor and fillDefaultColorFor:

 extension CalendarViewController: FSCalendarDelegateAppearance {

 // Return UIColor for numbers;

 func calendar(_ calendar: FSCalendar, 
               appearance: FSCalendarAppearance, 
               titleDefaultColorFor date: Date
 ) -> UIColor? {

      if self.eventsDateArray.contains(date) {
           return Colors.white 
           // Return UIColor for eventsDateArray 
      }

    return Colors.brownDark // Return Default Title Color
}

 // Return UIColor for Background;

func calendar(_ calendar: FSCalendar, 
            appearance: FSCalendarAppearance, 
            fillDefaultColorFor date: Date
) -> UIColor? {

    if self.eventsDateArray.contains(date) {
        return Colors.blue // Return UIColor for eventsDateArray
    }

    return Colors.white // Return Default UIColor 
}
}

Basically you have to check if your date is being displayed and then return a color to it.

If it doesn't work or you have questions, just call.

Related