@@ -20,6 +20,13 @@ final class DayCell: JTACDayCell {
2020 return label
2121 } ( )
2222
23+ lazy var circleView : UIView = {
24+ let view = UIView ( )
25+ view. backgroundColor = . red
26+ view. translatesAutoresizingMaskIntoConstraints = false
27+ return view
28+ } ( )
29+
2330 lazy var selectionBackgroundView : UIView = {
2431 let view = UIView ( )
2532 view. isHidden = true
@@ -46,6 +53,7 @@ final class DayCell: JTACDayCell {
4653 // MARK: - Variables
4754
4855 private var config : FastisConfig . DayCell = FastisConfig . default. dayCell
56+ private var todayConfig : FastisConfig . TodayCell ? = FastisConfig . default. todayCell
4957 private var rangeViewTopAnchorConstraints : [ NSLayoutConstraint ] = [ ]
5058 private var rangeViewBottomAnchorConstraints : [ NSLayoutConstraint ] = [ ]
5159
@@ -63,13 +71,22 @@ final class DayCell: JTACDayCell {
6371 fatalError ( " init(coder:) has not been implemented " )
6472 }
6573
74+ override func prepareForReuse( ) {
75+ super. prepareForReuse ( )
76+ self . circleView. removeFromSuperview ( )
77+ }
78+
6679 // MARK: - Configurations
6780
6881 public func applyConfig( _ config: FastisConfig ) {
6982 self . backgroundColor = config. controller. backgroundColor
7083
84+ let todayConfig = config. todayCell
7185 let config = config. dayCell
86+
87+ self . todayConfig = todayConfig
7288 self . config = config
89+
7390 self . rightRangeView. backgroundColor = config. onRangeBackgroundColor
7491 self . leftRangeView. backgroundColor = config. onRangeBackgroundColor
7592 self . rightRangeView. layer. cornerRadius = config. rangeViewCornerRadius
@@ -95,10 +112,8 @@ final class DayCell: JTACDayCell {
95112 public func configureConstraints( ) {
96113 let inset = self . config. rangedBackgroundViewVerticalInset
97114 NSLayoutConstraint . activate ( [
98- self . dateLabel. leftAnchor. constraint ( equalTo: self . contentView. leftAnchor) ,
99- self . dateLabel. rightAnchor. constraint ( equalTo: self . contentView. rightAnchor) ,
100- self . dateLabel. topAnchor. constraint ( equalTo: self . contentView. topAnchor) ,
101- self . dateLabel. bottomAnchor. constraint ( equalTo: self . contentView. bottomAnchor)
115+ self . dateLabel. centerXAnchor. constraint ( equalTo: self . contentView. centerXAnchor) ,
116+ self . dateLabel. centerYAnchor. constraint ( equalTo: self . contentView. centerYAnchor)
102117 ] )
103118 NSLayoutConstraint . activate ( [
104119 self . leftRangeView. leftAnchor. constraint ( equalTo: self . contentView. leftAnchor) ,
@@ -267,6 +282,7 @@ final class DayCell: JTACDayCell {
267282 var isSelectedViewHidden = true
268283 var isDateEnabled = true
269284 var rangeView = RangeViewConfig ( )
285+ var isToday = false
270286 }
271287
272288 internal func configure( for config: ViewConfig ) {
@@ -278,14 +294,11 @@ final class DayCell: JTACDayCell {
278294 if let dateLabelText = config. dateLabelText {
279295 self . dateLabel. isHidden = false
280296 self . dateLabel. text = dateLabelText
281- if !config. isDateEnabled {
282- self . dateLabel. textColor = self . config. dateLabelUnavailableColor
283- } else if !config. isSelectedViewHidden {
284- self . dateLabel. textColor = self . config. selectedLabelColor
285- } else if !config. rangeView. isHidden {
286- self . dateLabel. textColor = self . config. onRangeLabelColor
297+
298+ if config. isToday, let todayConfig {
299+ self . configureTodayCell ( viewConfig: config, todayConfig: todayConfig)
287300 } else {
288- self . dateLabel . textColor = self . config. dateLabelColor
301+ self . configureDayCell ( viewConfig : config)
289302 }
290303
291304 } else {
@@ -316,6 +329,46 @@ final class DayCell: JTACDayCell {
316329
317330 }
318331
332+ private func configureDayCell( viewConfig: ViewConfig ) {
333+ if !viewConfig. isDateEnabled {
334+ self . dateLabel. textColor = self . config. dateLabelUnavailableColor
335+ } else if !viewConfig. isSelectedViewHidden {
336+ self . dateLabel. textColor = self . config. selectedLabelColor
337+ } else if !viewConfig. rangeView. isHidden {
338+ self . dateLabel. textColor = self . config. onRangeLabelColor
339+ } else {
340+ self . dateLabel. textColor = self . config. dateLabelColor
341+ }
342+ }
343+
344+ private func configureTodayCell( viewConfig: ViewConfig , todayConfig: FastisConfig . TodayCell ) {
345+ self . dateLabel. font = todayConfig. dateLabelFont
346+
347+ if !viewConfig. isDateEnabled {
348+ self . dateLabel. textColor = todayConfig. dateLabelUnavailableColor
349+ self . circleView. backgroundColor = todayConfig. circleViewUnavailableColor
350+ } else if !viewConfig. isSelectedViewHidden {
351+ self . dateLabel. textColor = todayConfig. selectedLabelColor
352+ self . circleView. backgroundColor = todayConfig. circleViewSelectedColor
353+ } else if !viewConfig. rangeView. isHidden {
354+ self . dateLabel. textColor = todayConfig. onRangeLabelColor
355+ self . circleView. backgroundColor = todayConfig. onRangeLabelColor
356+ } else {
357+ self . dateLabel. textColor = todayConfig. dateLabelColor
358+ self . circleView. backgroundColor = todayConfig. circleViewColor
359+ }
360+
361+ self . circleView. layer. cornerRadius = todayConfig. circleSize * 0.5
362+ self . circleView. removeFromSuperview ( )
363+ self . contentView. addSubview ( self . circleView)
364+ NSLayoutConstraint . activate ( [
365+ self . circleView. centerXAnchor. constraint ( equalTo: self . dateLabel. centerXAnchor) ,
366+ self . circleView. topAnchor. constraint ( equalTo: self . dateLabel. bottomAnchor, constant: todayConfig. circleVerticalInset) ,
367+ self . circleView. widthAnchor. constraint ( equalToConstant: todayConfig. circleSize) ,
368+ self . circleView. heightAnchor. constraint ( equalToConstant: todayConfig. circleSize)
369+ ] )
370+ }
371+
319372}
320373
321374public extension FastisConfig {
@@ -325,7 +378,7 @@ public extension FastisConfig {
325378
326379 Configurable in FastisConfig.``FastisConfig/dayCell-swift.property`` property
327380 */
328- struct DayCell {
381+ class DayCell {
329382
330383 /**
331384 Font of date label in cell
@@ -400,4 +453,49 @@ public extension FastisConfig {
400453 public var customSelectionViewCornerRadius : CGFloat ?
401454 }
402455
456+ final class TodayCell : DayCell {
457+
458+ /**
459+ Size circle view in cell
460+
461+ Default value — `4pt`
462+ */
463+ public var circleSize : CGFloat = 4
464+
465+ /**
466+ Color of circle view in cell
467+
468+ Default value — `.label`
469+ */
470+ public var circleViewColor : UIColor = . systemBlue
471+
472+ /**
473+ Color of circle view in cell when date is unavailable for select
474+
475+ Default value — `.tertiaryLabel`
476+ */
477+ public var circleViewUnavailableColor : UIColor = . tertiaryLabel
478+
479+ /**
480+ Color of circle view in cell when date is selected
481+
482+ Default value — `.white`
483+ */
484+ public var circleViewSelectedColor : UIColor = . white
485+
486+ /**
487+ Color of circle view in cell when date is a part of selected range
488+
489+ Default value — `.label`
490+ */
491+ public var circleViewOnRangeColor : UIColor = . systemBlue
492+
493+ /**
494+ Inset circle view from date label
495+
496+ Default value — `5pt`
497+ */
498+ public var circleVerticalInset : CGFloat = 3
499+ }
500+
403501}
0 commit comments