【问题标题】:Allocate weekend day FSCalendar分配周末日 FSCalendar
【发布时间】:2018-01-27 07:53:28
【问题描述】:

我使用FSCalendar

我如何分配周末天?例如,红色周末,其他除了周末蓝色。我的意思是分配而不是星期中的(如星期天、星期六),即,即日期

星期一是 0 - 蓝色

星期二是 1 - 蓝色

...

星期六是 5 - 红色

星期日是 6 - 红色

星期一是 7 - 蓝色

...

星期六是 12 - 红色

星期天是 13 - 红色

等等

【问题讨论】:

    标签: ios swift xcode fscalendar


    【解决方案1】:

    使用Date 的扩展方法在您的willDisplayCell 方法中进行周末/工作日计算:

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

    根据是周末还是工作日,设置FSCalendarCell的以下属性:

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

    【讨论】:

    • 在方法cellForDateAtMonthPosition中你的意思是创建单元格? let cell = let cell = calendar.cell(for: date, at: .current) 并完成 return cell!?
    • 是的。出列一个单元格。如果出队的单元格为 nil,则创建自己的单元格并返回它。
    • 我明白,但我把identifier 换成dequeueReusableCell
    • 好的,然后在“willDisplayCell”方法中执行我在回答中提到的所有逻辑。那应该可以。
    【解决方案2】:

    我找到了以两个字符显示工作日名称的解决方案。您还可以更改我在下面提到的工作日标签的颜色,请检查。

    let weekdayEnumerator = calender.calendarWeekdayView.weekdayLabels
    weekdayEnumerator.forEach { (cell) in
    let c = cell
    let str = c.text ?? " "
    c.textColor = UIColor.red
    c.text = String(str.dropLast())
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-09
      • 2022-06-13
      • 1970-01-01
      • 1970-01-01
      • 2020-08-12
      • 1970-01-01
      • 2012-09-04
      • 1970-01-01
      相关资源
      最近更新 更多