Home>

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 {
         Honalara
     } else {
         Honalara
     }

    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 {
            case
                .unspecified,
                .light: return lightColor
            case .dark: return lightColor.inverted
            @unknown default:
                return lightColor
    }

    For reference only
    https://qiita.com/tamappe/items/5a6031d8b8d39f1e5b4e

Trends