美文网首页
UIColor Dark 模式获取不到正确值

UIColor Dark 模式获取不到正确值

作者: Ian_ | 来源:发表于2021-04-09 17:27 被阅读0次

在修改了 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

相关文章

网友评论

      本文标题:UIColor Dark 模式获取不到正确值

      本文链接:https://www.haomeiwen.com/subject/nyhwkltx.html