我正在使用FSCalendar,它仅显示默认假日,例如星期日(周末),因此我想在其中添加自己的假日并更改颜色。
因此,请任何人知道如何添加自定义假期吗????

最佳答案

我认为您必须在代码级别(如模型类(数组))上维护假期列表,或者可以使用数据库来存储假期列表。在渲染时,仅采用FSCalendarDelegateAppearance委托。这会为每个日期调用一个委托函数。

看示例,我认为它可以帮助您,

var datesWithHolidays = ["2018/09/03", "2018/10/06", "2018/09/12", "2018/10/25"]

//This is the delegate method
func calendar(_ calendar: FSCalendar, appearance: FSCalendarAppearance, fillDefaultColorFor date: Date) -> UIColor? {

    let dateString = self.dateFormatter1.string(from: date)
    if self.datesWithHolidays.contains(dateString) {
        return UIColor.green
    }
    return nil

}

关于ios - 在FSCalendar中添加自定义假期,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52476239/

10-14 02:07