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

前端 未结 16 1508
囚心锁ツ
囚心锁ツ 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 09:52

    Some nice extension maybe ?

    public extension UIViewController {
        @available(iOS 12.0, *)
        public var isDarkMode: Bool { traitCollection.userInterfaceStyle == .dark }
    }
    

提交回复
热议问题