uicolor - iOS13:如何在 Assets 目录中为提升的用户界面级别指定颜色

标签 uicolor ios13 uitraitcollection ios-darkmode

iOS 13 为我们带来 UIUserInterfaceLevel ,可以是 .base.elevated .系统似乎会自动调整提供给 UIView 的颜色。当在黑暗模式下使用升高的级别时。

但是,似乎没有办法手动指定.elevated颜色在 Assets 目录 ,或者是吗?

唯一的方法似乎是通过 the new UIColor constructor :

UIColor.init { (traits) -> UIColor in
   traits.userInterfaceLevel == .elevated ? UIColor(named: "myColor-elevated")! : UIColor(named: "myColor")!
}

最佳答案

据我所知,没有办法用颜色 Assets 做到这一点。

当您使用系统背景和填充颜色时,iOS 会在较高级别时自动选择“下一个更高”的颜色,即 .systemBackground变成 .secondarySystemBackground , 等等。

关于uicolor - iOS13:如何在 Assets 目录中为提升的用户界面级别指定颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58026941/

相关文章:

ios - 由变量组成的 UIColor

swift - AVPlayerViewController 视频适用于 iOS 11、12,但不适用于 iPhone 11 的 iOS 13

swift - iOS 13 : threading violation: expected the main thread

ios - Swift:如何在 IOS 9+ 中切换状态栏方向?

swift - Xcode 13 beta 5 错误 : UIViewController is missing its initial trait collection populated during initialization

objective-c - UITextField 边框动画

ios - 如何在 swift 3 中更改 TabBar 中禁用项目的颜色?

ios - 以编程方式创建具有颜色渐变的 UIView

ios - UITableView没有窗口iOS13时的UITableViewAlertForLayoutOutsideViewHierarchy