我正在使用FSCalendar,我想根据我的需求对其进行自定义。因此,我在一个视图控制器中有一个月份列表,并且同一个控制器有FSCalendar。我想要的是,当我点击任何特定的月份时,日历只会更改为该月份。
月份列表在集合视图中。在单击单元格时,我显示了上个月,但我不知道如何显示任何特定的月份。
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if let currentCell = collectionView.cellForItem(at: indexPath) as? AttendenceMonthCell {
// what code should I write here to get the particular month
let month = Calendar.current.date(byAdding: .month, value: -1, to: calender.currentPage)
calender.setCurrentPage(month!, animated: true)
}
}我已经用谷歌搜索了很多,但还没有得到任何答案。使用FSCalendar可以做到这一点吗?
发布于 2021-01-20 15:26:41
首先,找到当前月份并从选定的单元格索引中减去。就像这样。
let index = indexPath.item + 1
let currentMonth = Calendar.current.component(.month, from: Date())
let month = Calendar.current.date(byAdding: .month, value: index - currentMonth, to: calender.currentPage)
calender.setCurrentPage(month!, animated: true)https://stackoverflow.com/questions/65803959
复制相似问题