gpt4 book ai didi

ios - JTAppleCalendar Swift For 循环

转载 作者:搜寻专家 更新时间:2023-11-01 06:36:58 25 4
gpt4 key购买 nike

我正在使用以下函数尝试在您滚动日历时为每个标题打印出月份。我做 for 循环的方式肯定有问题,因为我离开的唯一月份是 12 月。有任何想法吗?谢谢

使用 print("(names)"),我在控制台上打印了所有月份。但是,我无法在视觉上正确打印出来。

func calendar(_ calendar: JTAppleCalendarView, willDisplaySectionHeader header: JTAppleHeaderView, range: (start: Date, end: Date), identifier: String) {

//let months: [String] = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
let months = Calendar.current.monthSymbols
let headerCell = (header as? MonthsHeader)
for names in months {
print("\(names)")
headerCell?.monthsHeader.text = names

}
}

最佳答案

这是你如何做的。

func calendar(_ calendar: JTAppleCalendarView, willDisplaySectionHeader header: JTAppleHeaderView, range: (start: Date, end: Date), identifier: String) {
let startDate = range.start
let month = myCalendar.dateComponents([.month], from: startDate).month!
let monthName = DateFormatter().monthSymbols[(month-1) % 12]
let year = testCalendar.component(.year, from: startDate)
let headerCell = header as? MyHeaderView
headerCell?.title.text = monthName + " " + String(year)
}

myCalendar --> 这是一个 Calendar() 实例

MyHeaderView->这是标题类

关于ios - JTAppleCalendar Swift For 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40393831/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com