Home Display Events from API in FSCalendar
Reply: 1

Display Events from API in FSCalendar

Ketan Odedra
1#
Ketan Odedra Published in 2018-02-14 07:19:42Z

This is my response from api

SUCCESS: { 
  "5": {
  "count": 1,
  "topEvent": false
  },
  "6": {
  "count": 1,
  "topEvent": false
  },
  "7": {
  "count": 3,
  "topEvent": true
  },
  "success": 1
}

In this response i have events in day 5,6 & 7, rest of the days there are no events. Now, I would need to show the count in the center of calendar icon and it should be green when the topEvent is true.

what logic i apply in

func calendar(_ calendar: FSCalendar, numberOfEventsFor date: Date) -> Int {

}

please help me..

Khawar Islam
2#
Khawar Islam Reply to 2018-02-14 07:47:27Z

If you have date parameter then To Set Events Base On Dates. Instance of DateFormatter And Variables:

var datesWithEvent = ["2015-10-03", "2015-10-06", "2015-10-12", "2015-10-25"]

var datesWithMultipleEvents = ["2015-10-08", "2015-10-16", "2015-10-20", "2015-10-28"]

fileprivate lazy var dateFormatter2: DateFormatter = {
    let formatter = DateFormatter()
    formatter.dateFormat = "yyyy-MM-dd"
    return formatter
}()

func calendar(_ calendar: FSCalendar, numberOfEventsFor date: Date) -> Int {

    let dateString = self.dateFormatter2.string(from: date)

    if self.datesWithEvent.contains(dateString) {
        return 1
    }

    if self.datesWithMultipleEvents.contains(dateString) {
        return 3
    }

    return 0
}

for highlight Event

func calendar(_ calendar: FSCalendar, appearance: FSCalendarAppearance, eventDefaultColorsFor date: Date) -> [UIColor]? {
        let key = self.dateFormatter2.string(from: date)
        if (self.remainderDates.contains(key)) {
            return [UIColor.red]
        }
        return nil
    }
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.632242 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO