我已經設定了FSCalendar的范圍模式為周。之后,我設定了標題日期格式 calendar.looks.headerDateFormat = "dd MMMM yyyy EEEE"
而且它顯示了正確的格式。
- 我所面臨的問題是,它給出了一周的開始日期。如果我選擇任何日期,我怎樣才能更新標題的值。 我沒有找到任何相關的屬性或方法。
- 我的選擇日期是2021年9月13日,但標題日期是2021年9月16日。
代碼和圖片已添加。
func setupFSCalendar() {
ViewCalendar.frame = CGRect(x。0, y: 78, width: view.frame.width, height: 100)
ViewCalendar.backgroundColor = ("#455a64").toColor()
let calendar = FSCalendar(frame: CGRect(x: 0, y: 0, width: ViewCalendar.frame.width, height: 250)
calendar.layoutIfNeeded()
calendar.dataSource = self
calendar.delegate = self
calendar.appearance.weekdayTextColor = .white //星期名稱顏色。
calendar.appearance.headerDateFormat = "dd MMMM yyyy EEEE"
calendar.appearance.headerTitleColor = UIColor.white
calendar.appearance.headerTitleFont = UIFont.systemFont(ofSize: 12)
calendar.appearance.titleWeekendColor = UIColor.white
calendar.appearance.titleDefaultColor = .white
calendar.scrollDirection = .horizontal
calendar.appearance.weekdayFont = UIFont.systemFont(ofSize: 12)
calendar.appearance.titleFont = UIFont.systemFont(ofSize: 18)
calendar.appearance.titleTodayColor = ("#54a767"/span>).toColor()
calendar.appearance.selectionColor = ("#788f9b") .toColor()
calendar.appearance.todayColor = nil
calendar.appearance.subtitleWeekendColor = UIColor.white
calendar.placeholderType =.none ///洗掉最后一個月的日期。
calendar.appearance.headerMinimumDissolvedAlpha = 0 //移除下一個月的標題。
calendar.backgroundColor = .clear
calendar.firstWeekday = 2
日歷.范圍 = .week
ViewCalendar.addSubview(calendar)
}
func calendar(_ calendar。FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) {
print(date)
calendar.setCurrentPage(date, animated: true)
calendar.select(date)
}
uj5u.com熱心網友回復:
你可以通過替換可見的FSCalendarHeaderCells的文本來實作,從選定的日期,如下所示
func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) {
print(date)
calendar.setCurrentPage(date, animated: true)
calendar.select(date)
//format the selectedDate and set to the header let dateFormatter = DateFormatter()
dateFormatter.dateFormat = calendar.appearance.headerDateFormat
for cell in calendar.calendarHeaderView.collectionView. visibleCells {
(cell as! FSCalendarHeaderCell).titleLabel.text = dateFormatter.string(from: date)
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/306785.html
標籤:


