In App Settings dark/light mode, doesnt change font color of time, date, notifications

397 Views Asked by At

When a user changes from dark/light mode from within the app, the top banner information does not change with it. Why?

enter image description here enter image description here

@IBAction func segmentedControlButtonClickAction(_ sender: UISegmentedControl) {
   if sender.selectedSegmentIndex == 0 {
      print("light mode")
    preferences.setValue("light", forKey: AppConstants.SHARED_PREF_LIGHT_OR_DARK_MODE)
    lightOrDark = "light"
    overrideUserInterfaceStyle = .light
    lightOrDarkOutlet.layer.borderColor = UIColor.black.cgColor
    setPillValue(value: pillLimit, btnSet: false)
    setPillResultsValue(value: pillNumPer, btnSet: false)
   }
   else {
      print("dark mode")
    preferences.setValue("dark", forKey: AppConstants.SHARED_PREF_LIGHT_OR_DARK_MODE)
    lightOrDark = "dark"
    overrideUserInterfaceStyle = .dark
    lightOrDarkOutlet.layer.borderColor = UIColor.white.cgColor
    setPillValue(value: pillLimit, btnSet: false)
    setPillResultsValue(value: pillNumPer, btnSet: false)
   }
}

What should I do to make sure this changes their device properly?

Updated the code and stiff doesnt work.

@IBAction func segmentedControlButtonClickAction(_ sender: UISegmentedControl) {
   if sender.selectedSegmentIndex == 0 {
        print("light mode")
        preferences.setValue("light", forKey: CSNAppConstants.SHARED_PREF_LIGHT_OR_DARK_MODE)
        lightOrDark = "light"
        overrideUserInterfaceStyle = .light
        lightOrDarkOutlet.layer.borderColor = UIColor.black.cgColor
        setPillValue(value: ebayLimit, btnSet: false)
        setPillResultsValue(value: ebayNumPer, btnSet: false)
        self.setNeedsStatusBarAppearanceUpdate()
   } else {
        print("dark mdoe")
        preferences.setValue("dark", forKey: CSNAppConstants.SHARED_PREF_LIGHT_OR_DARK_MODE)
        lightOrDark = "dark"
        overrideUserInterfaceStyle = .dark
        lightOrDarkOutlet.layer.borderColor = UIColor.white.cgColor
        setPillValue(value: ebayLimit, btnSet: false)
        setPillResultsValue(value: ebayNumPer, btnSet: false)
        self.setNeedsStatusBarAppearanceUpdate()
   }
    
}

override var preferredStatusBarStyle: UIStatusBarStyle {
    if (lightOrDark == "light") {
        return .darkContent
    }
    return .lightContent
}
1

There are 1 best solutions below

1
On

Try this in the view controller:

override var preferredStatusBarStyle: UIStatusBarStyle {
    traitCollection.userInterfaceStyle == .light ? .darkContent : .lightContent
}