首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Swift中JTAppleCalendar中日期标签下的月份名称

Swift中JTAppleCalendar中日期标签下的月份名称
EN

Stack Overflow用户
提问于 2018-06-12 16:10:03
回答 1查看 636关注 0票数 1

我正在尝试youtube上的JTAppleCalendar教程。在这里,我制作了一个自定义日历,在这个日历中,我试图在日期标签下显示当前月份的名称。我还在视图顶部获得了月份名称。当我传递月份名值时,它会正确地显示在视图的顶部,但是当我传递给单元格中的标签时,它只显示标签文本,而不显示月份名称。我怎样才能在那里得到月份名称?我的日历代码是这样的:

代码语言:javascript
复制
func setUpViewForCalendar(from visibleDate: DateSegmentInfo){

    let date  = visibleDate.monthDates.first?.date
    self.formatter.dateFormat = "yyyy MM dd"
    self.yearLbl.text = self.formatter.string(from: date!)
    self.formatter.dateFormat = "MMMM"
    self.monthLbl.text = self.formatter.string(from: date!)
}
extension ViewController : JTAppleCalendarViewDataSource{
func calendar(_ calendar: JTAppleCalendarView, willDisplay cell: JTAppleCell, forItemAt date: Date, cellState: CellState, indexPath: IndexPath) {

}

func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {
    formatter.dateFormat = "yyyy MM dd"
    formatter.timeZone = Calendar.current.timeZone
    formatter.locale = Calendar.current.locale

    let startDate = formatter.date(from: "2018 01 01")
    let endDate = formatter.date(from: "2018 12 31")

    let parameter = ConfigurationParameters(startDate: startDate!, endDate: endDate!)
    return parameter
}

}

代码语言:javascript
复制
extension ViewController : JTAppleCalendarViewDelegate{

func calendar(_ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell {
    let cell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: "customCell", for: indexPath) as! CustomCell
    cell.dateLbl.text = cellState.text
    cell.monthLbl.text = self.monthLbl.text
    print(cell.monthLbl.text)
    handleCellTextColor(view: cell, cellState: cellState)
    return cell
}

func calendar(_ calendar: JTAppleCalendarView, didSelectDate date: Date, cell: JTAppleCell?, cellState: CellState) {
    handleCellTextColor(view: cell!, cellState: cellState)
}

func calendar(_ calendar: JTAppleCalendarView, didDeselectDate date: Date, cell: JTAppleCell?, cellState: CellState) {
    handleCellTextColor(view: cell!, cellState: cellState)
}

func calendar(_ calendar: JTAppleCalendarView, didScrollToDateSegmentWith visibleDates: DateSegmentInfo) {
    setUpViewForCalendar(from: visibleDates)
}

}

我的日历是这样的,

EN

回答 1

Stack Overflow用户

发布于 2019-09-17 04:08:02

代码语言:javascript
复制
let formatter = DateFormatter()
formatter.dateFormat = "MMMM"

func calendar(_ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell {
    let cell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: "customCell", for: indexPath) as! CustomCell
    cell.dateLbl.text = cellState.text
    cell.monthLbl.text = formatter.string(from: date)
    print(cell.monthLbl.text)
    handleCellTextColor(view: cell, cellState: cellState)
    return cell
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50812246

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档