gpt4 book ai didi

ios - 我想创建自定义日历所以我使用了 JTAppleCalendar 并想在 Collection View 单元格中显示日期

转载 作者:行者123 更新时间:2023-11-28 21:03:45 32 4
gpt4 key购买 nike

我想创建自定义日历,所以我为此使用了 JTAppleCalendar 我采用了一个 Collection View 并想在 Collection View 单元格中显示日期,但它没有显示应该如何解决这个问题?

CalendarViewController.swift

import UIKit
import JTAppleCalendar

class CalendarViewController: UIViewController {

@IBOutlet weak var calendarView: JTAppleCalendarView!

override func viewDidLoad() {
super.viewDidLoad()

self.calendarView.calendarDataSource = self
self.calendarView.calendarDelegate = self
// Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

}

extension CalendarViewController:JTAppleCalendarViewDelegate,JTAppleCalendarViewDataSource{

func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {

let formatter = DateFormatter()

formatter.dateFormat = "yyyy MM dd"
formatter.timeZone = Calendar.current.timeZone
formatter.locale = Calendar.current.locale

let startdate = formatter.date(from: "2017 01 01")!
let enddate = formatter.date(from: "2017 12 31")!
let parameters = ConfigurationParameters(startDate: startdate, endDate: enddate)
// print(formatter.string(from: startdate))
return parameters
}

func calendar(_ calendar: JTAppleCalendarView, willDisplay cell: JTAppleCell, forItemAt date: Date, cellState: CellState, indexPath: IndexPath) {

}

func calendar(_ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell {

let cell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: "CalendarCell", for: indexPath) as! CalendarCell

cell.dateLabel.text = cellState.text

return cell
}
}



CalendarCell.swift

import UIKit
import JTAppleCalendar
class CalendarCell: JTAppleCell {


@IBOutlet weak var dateLabel: UILabel!
}

最佳答案

calendarView.registerCellViewXib(file: "CalendarDateCell")
calendarView.delegate = self
calendarView.dataSource = self
calendarView.direction = .horizontal
calendarView.selectDates([selectedDate])
calendarView.reloadData()

在viewdidLoad()中添加

关于ios - 我想创建自定义日历所以我使用了 JTAppleCalendar 并想在 Collection View 单元格中显示日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46904336/

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