if let navigationBar = navigationController?.navigationBar {
navigationBar.isTranslucent = true
navigationBar.shadowImage = UIImage()
navigationBar.tintColor = Color.grey1.uiColor
navigationBar.setBackgroundImage(UIImage.createImage(withColor: UIColor.white.withAlphaComponent(0.92)), for: .default)
navigationBar.titleTextAttributes = [
.font: Font.monoBold.uiFont(ofSize: 17),
.foregroundColor: navigationBar.tintColor
]
}
编译器将navigationBar
标记为非可选UINavigationBar
。
这是有道理的,因为我们正在if let
对其进行包装
在UINavigationBar
的界面中,它具有此属性tintColor
open var tintColor: UIColor!
所以navigationBar.tintColor
似乎是非可选的吧?
但是,编译器决定在此处不同意:
从“ UIColor”隐式强制的表达?到“任何”
为什么编译器突然认为tintColor
是可选的UIColor?