问题描述
iOS 13 为我们带来了 UIUserInterfaceLevel
,它可以是 .base
或 .elevated
.当在黑暗模式下使用提升的级别时,系统似乎会自动调整提供给 UIView
的颜色.
iOS 13 brings us UIUserInterfaceLevel
, which can be either .base
or .elevated
. The system seems to automatically adjust colors provided to UIView
when the elevated level is used in dark mode.
但是好像没有办法手动指定.elevated
颜色在资产目录,是吗?
However, there seems to be no way how to manually specify the .elevated
color in the asset catalog, or is it?
唯一的方法似乎是通过新的 UIColor 构造函数:
The only way how to do it seems to be via the new UIColor constructor:
UIColor.init { (traits) -> UIColor in
traits.userInterfaceLevel == .elevated ? UIColor(named: "myColor-elevated")! : UIColor(named: "myColor")!
}
推荐答案
据我所知,颜色资产无法做到这一点.
There is no way to do that with color assets, as far as I know.
当您使用系统背景和填充颜色时,iOS 会在提升级别时自动选择下一个更高"的颜色,即 .systemBackground
变为 .secondarySystemBackground
等
When you use the system background and fill colors, iOS will automatically pick the "next higher" color when on an elevated level, i.e., .systemBackground
becomes .secondarySystemBackground
, etc.
这篇关于iOS13:如何在资产目录中为提升的用户界面级别指定颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!