How to change the image on selecting date in FSCalendar in swift 3.x?

1.8k views Asked by At

For setting the images i am doing like this

func calendar(_ calendar: FSCalendar, imageFor date: Date) ->     
      UIImage? {
    let day: Int! = self.gregorian.component(.day, from: date)
    if day == 6 || day == 10{
        return UIImage(named: "event_calender")
    }else if day == 7 || day == 14{
        return UIImage(named: "holiday_calender_line")
    }
    else if day == 7 || day == 14{
        return UIImage(named: "birthday_calender_line")
    }
    else{
         return [13,4].contains(day) ? UIImage(named: "icon_cat") : nil
    }
}

but how i can change the seleted date image from this delegate method

func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) {
    print("calendar did select date \(self.formatter.string(from: date))")
}

say current image is "holiday_calender_line" and on selection imwant to change with "holiday_calender_solid".

1

There are 1 answers

0
Joseph Mikko Manoza On

try this ..

let holidays:  [Date] = []
let events:    [Date] = []
let birthdays: [Date] = []

func calendar(_ calendar: FSCalendar, imageFor date: Date) -> UIImage? {

    if holidays.contains(date) {
        return holidays.contains(date) ? UIImage(named: "holiday_calender_line") : nil
    } else if events.contains(date) {
        return events.contains(date) ? UIImage(named: "event_calender") : nil
    } else if birthdays.contains(date) { 
        return birthdays.contains(date) ? UIImage(named: "birthday_calender_line") : nil
    } 

   return nil
}