首页 > 解决方案 > iOS13如何适应图像暗模式?

问题描述

如果我不将图像添加到资产中,我只是将图像添加到我的 Xcode 项目包中,我如何命名图像以便 Xcode 可以判断它是暗模式的图像!

标签: imageios13ios-darkmode

解决方案


请覆盖 func 并为深色和浅色模式提供不同的图像。

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
    super.traitCollectionDidChange(previousTraitCollection)
    if #available(iOS 12.0, *) {
        let isDark = traitCollection.userInterfaceStyle == .dark ? true : false
        if isDark{
            updateUIForiOS13DarkMode()
        }else{
            updateUIForiOS13LightMode(
        }
    }
}

推荐阅读