image - iOS13如何适应图像暗模式?
问题描述
如果我不将图像添加到资产中,我只是将图像添加到我的 Xcode 项目包中,我如何命名图像以便 Xcode 可以判断它是暗模式的图像!
解决方案
请覆盖 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(
}
}
}
推荐阅读
- php - 与数据透视表 Laravel 的关系中的错误
- json - 使用 JOLT 规范过滤数组时如何使用“不等于”条件
- c - 用 C 编写的程序,使用 3 位数字但不能使用 5 位数字
- python - 获取最小 MSE python 的路径
- javascript - 使用变量作为角度的火力参考
- excel - 在 Excel 中禁用非标准本地格式
- c# - 如何使用 ClosedXML 打开受保护的 Excel 文件?
- python - Python 的依赖注入和自定义pickler
- adobe-analytics - Segment Builder - 在多个 URL 中“粘贴”的任何方式(由于不同的名称约定/等)?
- mongodb - Pymongo - 查找多个不同的文档