UIWindow.appearance (). overrideUserInterfaceStyleorself.overrideUserInterfaceStyleon any UIViewController can only take.unspecified.

How can I get the current appearance mode (.darkor.light) (which mode is currently displayed)? Please let me know if you know.

  • Answer # 1

    I was out of focus, I used it elsewhere

    if traitCollection.userInterfaceStyle == .dark {
     } else {

    I confusedoverrideUserInterfaceStylewithtraitCollection.userInterfaceStyle

  • Answer # 2

    I don't think I have looked at it.
    The user can choose light or dark, so just think about the color in the dark.

    Implementation example (in dark mode, simply return the opposite color of normal lightColor)

    UIColor {(traitCollection: UITraitCollection)->UIColor in
        switch traitCollection.userInterfaceStyle {
                .light: return lightColor
            case .dark: return lightColor.inverted
            @unknown default:
                return lightColor

    For reference only