How can I check whether dark mode is enabled in iOS/iPadOS?

前端 未结 16 1502
囚心锁ツ
囚心锁ツ 2020-12-08 09:41

Starting from iOS/iPadOS 13, a dark user interface style is available, similar to the dark mode introduced in macOS Mojave. How can I check whether the user has enabled the

16条回答
  •  悲&欢浪女
    2020-12-08 10:01

    For iOS 13, you can use this property to check if current style is dark mode or not:

    if #available(iOS 13.0, *) {
        if UITraitCollection.current.userInterfaceStyle == .dark {
            print("Dark mode")
        }
        else {
            print("Light mode")
        }
    }
    

提交回复
热议问题