如何重拍本周开始,而不是从周日开始,而是从周一开始

问题描述 投票:-1回答:1

我使用图书馆显示日历,我想在星期一开始一周,日历从2017年的当前日期开始显示

https://github.com/miraan/CalendarDateRangePickerViewController

Image

改变了俄语的语言环境,但没有帮助

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!)
}
ios swift uidatepicker
1个回答
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 = ""
© www.soinside.com 2019 - 2024. All rights reserved.