我使用库显示日历,我想将星期从星期一开始,并从2017年的当前日期开始显示日历
https://github.com/miraan/CalendarDateRangePickerViewController
更改了俄语的语言环境,但没有帮助
func getMonthLabel(date: Date) -> String {
var dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "ru_RU")
dateFormatter.dateFormat = "MMMM yyyy"
return dateFormatter.string(from: date)
}
func getWeekdayLabel(weekday: Int) -> String {
var components = DateComponents()
components.calendar = Calendar.current
components.weekday = weekday
let date = Calendar.current.nextDate(after: Date(), matching: components, matchingPolicy: Calendar.MatchingPolicy.strict)
if date == nil {
return "E"
}
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "ru_RU")
dateFormatter.dateFormat = "EEEEE"
return dateFormatter.string(from: date!)
}
答案 0 :(得分:0)
问题出在代码的这一部分,用2纠正,并设法获得了预期的结果。
override public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellReuseIdentifier, for: indexPath) as! CalendarDateRangePickerCell
cell.reset()
let blankItems = getWeekday(date: getFirstDateForSection(section: indexPath.section)) - 1
if indexPath.item < 7 {
cell.label.text = getWeekdayLabel(weekday: indexPath.item **+ 2** )
} else if indexPath.item < 7 + blankItems {
cell.label.text = ""