UIColor Dark 模式获取不到正确值

2021-04-09  本文已影响0人  Ian_

在修改了 keyWindow 的 userInterfaceStyle 后, 使用自定义 status bar style,
UIColor 的 userInterfaceStyle 会受其影响, 有时候会拿不到正确的值

let c = UIColor { (trait) -> UIColor in
    switch trait.userInterfaceStyle {
    case .dark:
        return .black
    default:
        return .white
    }
}

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
}

解决办法, 根据 View 自己的 userInterfaceStyle, 获取 color, 如下:

c = c.resolvedColor(with: trait)

reference

上一篇 下一篇

猜你喜欢

热点阅读