Как мы поддерживаем темный режим в текущем приложении iOS с iOS 13? - PullRequest
1 голос
/ 20 июня 2019

Мое текущее приложение разработано в objC и Swift.Мне нужно поддержать темный режим.Кто-нибудь может подсказать, как я могу добиться этого глобально?

1 Ответ

1 голос
/ 11 июля 2019
Hi Pushp, 

There are couples of semantic system color are available in interface builder of Xcode11-beta. please use those to support both .light and .darkMode

Please follow the basics instructions step by step.

1) UIView - use systemBackgroundColor from interface builder.
2) UILabel - use defaulLabel color from interface builder.
3) CustomView - Please use .xcassests catalog and create **new color set**, add **appearances** option from **attributes inspector** for .light and .darkMode and provide different color for both mode.
4) CustomImages - Please use .xcassests catalog and add **appearances** option from **attributes inspector** for .light and .darkMode and provide different images for both mode.
5) There is also an option to provide different color and different images using code. 

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
        super.traitCollectionDidChange(previousTraitCollection)
        updateUIForiOS13()
    }

    private func isDarkMode() -> Bool{
        if #available(iOS 12.0, *) {
            let isDark = traitCollection.userInterfaceStyle == .dark ? true : false
            return isDark
        }
        return false
    }
...