FSCalendar Dark Mode issue for title color

FSCalendar is a very good calendar library in Swift but it does not support dark mode, I’m using version 2.8.1.

We can easily change all date color by one of its delegate’s FSCalendarDelegateAppearance func.

func calendar(_ calendar: FSCalendar, appearance: FSCalendarAppearance, titleDefaultColorFor date: Date) -> UIColor? {
        
        let defaultColor = appearance.titleDefaultColor
        
        if #available(iOS 12.0, *) {
            if self.traitCollection.userInterfaceStyle == .dark {
                return .orange
            } else {
                return defaultColor
            }
        } else {
            return defaultColor
        }
        
    }

Also, don’t forget to reload the calendar data

override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
        self.calendar?.reloadData()
    }
Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •