我正在使用库CVCalendar for Swift,我正在尝试自定义日历的外观。 我有一个名为“FirstViewController”的ViewController,其中包含日历的UIView。在我的文件FirstViewController.swift中,我设法实现了CVCalendar提供API函数的属性自定义。
但我不知道定制其他没有这些功能API的属性的正确方法是什么。例如,CVCalendar的类CVCalendarViewAppearanceDelegate有许多属性,其默认值可以修改,例如dayLabelWeekdayInTextColor。
问题:如何正确修改属性,例如来自FirstViewController.swift的“dayLabelWeekdayInTextColor”?
注意我创建了一个函数setupCalendarFormat(),我正在修改属性;我尝试在viewDidLoad()和viewDidLayoutSubviews()中调用它,但修改无法正常工作。
我的代码如下:
import UIKit
import CVCalendar
class FirstViewController: UIViewController {
@IBOutlet weak var containerView: UIView!
@IBOutlet weak var menuView: CVCalendarMenuView!
@IBOutlet weak var calendarView: CVCalendarView!
override func viewDidLoad() {
super.viewDidLoad()
//self.view.layoutIfNeeded()
setupCalendarFormat()
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
//setupCalendarFormat()
menuView.commitMenuViewUpdate()
calendarView.commitCalendarViewUpdate()
}
func setupCalendarFormat(){
//CircleView background color and alpha
calendarView.appearance.dayLabelPresentWeekdayHighlightedBackgroundColor = UIColor.black //not working highlight color not changing to black
//day numbers' color
calendarView.appearance.dayLabelWeekdayInTextColor = UIColor.green // not working correctly, color is only changing to green after i select the number
calendarView.appearance.dayLabelPresentWeekdayTextColor = UIColor.green // working , probably becuase by default the present day is selected
}
}
extension FirstViewController: CVCalendarViewDelegate, CVCalendarMenuViewDelegate{
//All these APIs are succesfully called
func presentationMode() -> CalendarMode {
return .weekView
}
func firstWeekday() -> Weekday {
return .sunday
}
func dayOfWeekFont() -> UIFont {
return UIFont.systemFont(ofSize: 12.0, weight: .medium)
}
func dayOfWeekTextColor() -> UIColor {
return .black
}
func dayOfWeekTextUppercase() -> Bool {
return false
}
func shouldShowWeekdaysOut() -> Bool {
return true
}
}
答案 0 :(得分:0)
CVCalendar
存储库为您提供了一个CVCalendar Demo
,演示了如何设置日历元素的颜色。
它基本上是这样的:
CVCalendar
当日历即将显示例如文本元素时,它会通过调用特定方法向其委托(您的视图控制器)询问颜色,该方法将根据您的逻辑返回UIColor
,例如:
extension ViewController: CVCalendarViewDelegate, CVCalendarMenuViewDelegate {
func dayOfWeekTextColor(by weekday: Weekday) -> UIColor {
return weekday == .sunday ? UIColor(red: 1.0, green: 0, blue: 0, alpha: 1.0) : UIColor.white
}
}