2017-07-12 33 views
0

我有對象的數組包含預訂高亮天如果日期等於日期在陣列(JTAppleCalendar)

class MonthBookings: NSObject { 

    var date: Date = Date()  
    var bookings_count: Int = 0 
} 

var bookings = [MonthBookings]() 

所以我需要檢查,如果細胞日期是在預訂陣列然後改變細胞等於某個日期單元格中此日期的顏色。

我試圖向下跌破這一方式,但沒有奏效:

func calendar(_ calendar: JTAppleCalendarView, willDisplayCell cell: JTAppleDayCellView, date: Date, cellState: CellState) { 
    guard let sfbCell = cell as? SFBCalendarCell else {return} 

    let booking = self.bookingsMonths[cellState.row()] 

    if booking.date == date { 
     sfbCell.dayText.textColor = .red 
    } else { 
     sfbCell.dayText.textColor = .black 
    } 
} 

回答

0

我用解決方法包含

if bookingsMonths.contains(where: { $0.date == cellState.date && $0.bookings_count != 0 }) { 

     sfbCell.dayText.font = UIFont.boldSystemFont(ofSize: 15) 

} else { 

     sfbCell.dayText.font = UIFont.systemFont(ofSize: 15) 

} 
0

你是day比較或做實際的日期/時間? 嘗試這樣的事情。

let order = CalendarManager.currentCalendar.compare(cellState.date, to: 
Date(), toGranularity: .day) 
    if order == .orderedSame { 
    calendarCell.dayNumberLabel.textColor = UIColor.white 
    } 
+0

我解決它通過使用含有方法 –

相關問題