gpt4 book ai didi

ios - 如何将日期信息传递给 CVCalendar 进行显示?

转载 作者:行者123 更新时间:2023-11-30 12:55:59 24 4
gpt4 key购买 nike

我无法弄清楚(文档中也不清楚)如何向 CVCalendar 提供信息,以便它可以决定是否在给定日期显示点。另外,如何显示与所选日期相关的文本信息?

CVCalendar 附带了一些方法,用于选择是否在给定日期显示点以及在选择日期时执行操作,但不会告诉您如何实际将该信息传递到日历。有没有简单的方法可以做到这一点?

最佳答案

我能想到的最优雅的方法来处理这个问题是使用字典,以便日历可以在字典中查找日期,而不是迭代数组中的日期

var datesDictionary:[String:String] = ["5 November, 2016":"First item","9 November, 2016":"Second item","20 November, 2016":"Third item"]

完整代码如下。您需要按照The documentation在 Storyboard中设置 View 和委托(delegate)。以及主视图 Controller 中的 UITextView (dayTextView)

import UIKit
import CVCalendar

class ViewController: UIViewController,CVCalendarMenuViewDelegate,CVCalendarViewDelegate {

@IBOutlet weak var menuView: CVCalendarMenuView!
@IBOutlet weak var calendarView: CVCalendarView!
@IBOutlet var dayTextView:UITextView!

var datesDictionary:[String:String] = ["5 November, 2016":"Service","9 November, 2016":"Change Oil","20 November, 2016":"Check brakes"]

func dotMarker(shouldShowOnDayView dayView: DayView) -> Bool{
// Look up date in dictionary
if(datesDictionary[dayView.date.commonDescription] != nil){
return true // date is in the array so draw a dot
}
return false
}
func dotMarker(colorOnDayView dayView: DayView) -> [UIColor]{
return [UIColor.black]
}

func didSelectDayView(_ dayView: DayView, animationDidFinish: Bool){

dayTextView.text = ""
// Look up date in dictionary
if(datesDictionary[dayView.date.commonDescription] != nil){
dayTextView.text = datesDictionary[dayView.date.commonDescription] // day is in the dictionary - wrote the corresponding text to dayTextView
}
}

override func viewDidLoad() {
super.viewDidLoad()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
menuView.commitMenuViewUpdate()
calendarView.commitCalendarViewUpdate()
}

func presentationMode() -> CalendarMode{
return .monthView
}
func firstWeekday() -> Weekday{
return .monday
}
}

关于ios - 如何将日期信息传递给 CVCalendar 进行显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40386910/

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