FSCalendar:获取当前视图的开始和结束日期

时间:2017-07-24 14:33:32

标签: swift3 fscalendar

如何获取当前日历的开始和结束日期?

从截图中,我需要获得2017年9月24日和2017年11月4日..

感谢![enter image description here] 1

2 个答案:

答案 0 :(得分:1)

在这里您可以看到第一个和最后一个可见日期

let startDate: Date?
let endDate: Date?
if self.calendar.scope == .week {
    startDate = self.calendar.currentPage
    endDate = self.calendar.gregorian.date(byAdding: .day, value: 6, to: startDate)
} else { // .month
    let indexPath = self.calendar.calculator.indexPath(for: self.calendar.currentPage, scope: .month)
    startDate = self.calendar.calculator.monthHead(forSection: (indexPath?.section)!)!
    endDate = self.calendar.gregorian.date(byAdding: .day, value: 41, to: startDate)
}

docs

答案 1 :(得分:0)

var dateArray = [Date]()
for cell:FSCalendarCell in calendar.visibleCells() {
  if cell.isPlaceholder {
    dateArray.append(calendar.date(for: cell)!)
  }
}

calendar.select(dateArray.min())
calendar.select(dateArray.max())