【问题标题】:How to get explicitly light or dark color from ColorSet?如何从 ColorSet 中获得明确的浅色或深色?
【发布时间】:2020-09-01 11:16:48
【问题描述】:

使用UIColor.init(named: "customColorSet")从ColorSet中获取与当前userInterfaceStyle匹配的颜色是没有问题的。

但是,如何从颜色集中获取特定颜色,例如浅色还是深色?

我尝试使用UIColor.init(named: "customColorSet", in: nil, compatibleWith: UITraitCollection(userInterfaceStyle: .light)),但它似乎不起作用,因为仍然返回与当前userInterfaceStyle 匹配的颜色(在我的情况下是深色)。

【问题讨论】:

标签: swift uicolor ios-darkmode


【解决方案1】:

您可以使用UIColor.resolvedColor(with:)

测试:

let color = UIColor(named: "Color")?.resolvedColor(with: UITraitCollection(userInterfaceStyle: .light))
let rgb = color!.cgColor.components

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-29
    • 1970-01-01
    • 2012-07-11
    • 1970-01-01
    • 2010-09-10
    • 2017-07-12
    • 2017-06-26
    • 1970-01-01
    相关资源
    最近更新 更多