swift3 – 如何在FSCalendar swift 3中更改事件数组的背景颜色?

前端之家收集整理的这篇文章主要介绍了swift3 – 如何在FSCalendar swift 3中更改事件数组的背景颜色?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有2个日期并希望为特定事件设置不同的颜色,请帮助如何做到这一点.

我正在尝试实现以下代码,但它没有工作它的返回零没有颜色效果没有错误没有什么被困在这请求帮助.

import UIKit
import FSCalendar

class myCalendarViewController: UIViewController,FSCalendarDelegate,FSCalendarDataSource,FSCalendarDelegateAppearance {

    var presentdays = [String]()
    var absentdays = [String]()

@IBOutlet weak var calendar: FSCalendar!

fileprivate let gregorian: Calendar = Calendar(identifier: .gregorian)
fileprivate lazy var dateFormatter1: DateFormatter = {
   let formatter = DateFormatter()
   formatter.dateFormat = "yyyy/MM/dd"
   return formatter
}()

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

func calendar(_ calendar: FSCalendar,appearance: FSCalendarAppearance,titleDefaultColorFor date: Date) -> UIColor? {
         presentdays = ["2017-06-03","2017-06-06","2017-06-12","2017-06-25"]

         absentdays = ["2017-06-10","2017-06-18","2017-06-15","2017-06-16"]

let datestring2 : String = dateFormatter1.string(from:date)

if presentdays.contains(datestring2)
{
    return UIColor.green
}
else if absentdays.contains(datestring2)
{
    return UIColor.red
}
else{
    return nil
}

}
   }
DateFormatter的dateFormat和数组中的字符串日期不匹配,因此将dateFormat更改为yyyy-MM-dd,然后检查数组是否包含对象.
fileprivate lazy var dateFormatter1: DateFormatter = {
    let formatter = DateFormatter()
    formatter.dateFormat = "yyyy-MM-dd"
    return formatter
}()
原文链接:https://www.f2er.com/swift/319961.html

猜你在找的Swift相关文章