【发布时间】:2018-01-21 18:32:45
【问题描述】:
我制作了一个自定义 UINavigationBar,我想在全球范围内使用它。我在其他示例中看到,要全局设置 UINavigationBar 外观,您必须在 AppDelegate 中执行类似 let navigationBar = UINavigationBar.appearance() 的操作。然后就可以设置属性了。就我而言,我已经在class var 中设置了所有属性,如下所示:
extension UINavigationBar {
class var customNavBar : UINavigationBar{
let navigationBar = UINavigationBar()
navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "Avenir-Black", size: 40)!, NSForegroundColorAttributeName: UIColor.RED]
//gets rid of black separation bar
navigationBar.shadowImage = UIImage()
navigationBar.setBackgroundImage(UIImage(), for: .any, barMetrics: .default)
//set the background color to white
navigationBar.tintColor = UIColor.white
navigationBar.isTranslucent = false
return navigationBar
}
}
现在,如何将 UINavigationBar 从 AppDelegate 设置为固有的这些属性。我的意思是在应用程序委托中有这样的东西。或类似的当然。 在 AppDelegate 中:
let navigationBar = UINavigationBar.customNavBar.appearance()
我想这样做的原因是因为我有一些其他的UIViewControllers(与我的TabViewController 不同),我想在其中手动添加 UINavigationBar 并且它必须看起来像自定义一个。
【问题讨论】:
-
你在设置 UINavigationBar.appearance() 的属性吗?例如UINavigationBar.appearance().tintColor = .red
-
@andrehungaro 确实,但我想在我的应用程序委托中调用我的 customNavBar
标签: ios swift uinavigationbar navigationbar uiapplicationdelegate