Created
October 29, 2019 09:45
-
-
Save boborbt/d1aca6c8fcd00a10db5ffc4aea3038e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// DayCellView.swift | |
// T-Shifts | |
// | |
// Created by Roberto Esposito on 09/02/2017. | |
// Copyright © 2017 Roberto Esposito. All rights reserved. | |
// | |
import Foundation | |
import JTAppleCalendar | |
import TShiftsFramework | |
import OSLog | |
class DayCellView: JTACDayCell { | |
@IBOutlet weak var label: UILabel! | |
@IBOutlet weak var selectionEmphasis: UIView! | |
@IBOutlet weak var marksDisplayView: MarksDisplayView! | |
enum ColorEmphasis { | |
case normal | |
case dim | |
case hidden | |
} | |
var isToday: Bool = false { | |
didSet { | |
updateMarksColor() | |
updateLabelColor() | |
} | |
} | |
var colorEmphasis: ColorEmphasis = .normal { | |
didSet { | |
updateLabelColor() | |
updateMarksColor() | |
} | |
} | |
var showEmphasis: Bool = false | |
var showTodayMark: Bool = false | |
var marks: [ShiftTemplate] = [] { | |
didSet { | |
marksDisplayView.marks = marks | |
} | |
} | |
var isEmphasized: Bool { | |
get { | |
return showEmphasis | |
} | |
set(newVal) { | |
showEmphasis = newVal | |
selectionEmphasis.layer.cornerRadius = 5 | |
selectionEmphasis.alpha = newVal ? 1.0 : 0.0 | |
} | |
} | |
private func updateMarksColor() { | |
switch colorEmphasis { | |
case .normal: | |
self.alpha = 1.0 | |
case .dim: | |
self.alpha = 0.3 | |
case .hidden: | |
self.alpha = 0.0 | |
} | |
} | |
private func updateLabelColor() { | |
if isToday { | |
label.textColor = UIColor.red | |
return | |
} | |
label.textColor = UIColor.black | |
} | |
override func prepareForReuse() { | |
self.colorEmphasis = .normal | |
self.isToday = false | |
marksDisplayView.marks = [] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment