Ios QLPreviewController';第一次打开时,其颜色不同
每当我打开Ios QLPreviewController';第一次打开时,其颜色不同,ios,swift,user-interface,uinavigationbar,qlpreviewcontroller,Ios,Swift,User Interface,Uinavigationbar,Qlpreviewcontroller,每当我打开qlviewcontroller时,tintColor默认为粉红色。我希望它是一种特定的颜色,所以我就这样设置它 UINavigationBar.appearance().tintColor = UIColor.hexStringToUIColor(hexStr: "202020") 这就是调出qlviewcontroller的方法的样子 func openQLPreview() { quickLookController = QLPreviewController()
qlviewcontroller
时,tintColor
默认为粉红色。我希望它是一种特定的颜色,所以我就这样设置它
UINavigationBar.appearance().tintColor = UIColor.hexStringToUIColor(hexStr: "202020")
这就是调出qlviewcontroller
的方法的样子
func openQLPreview() {
quickLookController = QLPreviewController()
UINavigationBar.appearance().tintColor = UIColor.hexStringToUIColor(hexStr: "202020")
quickLookController.dataSource = self
self.navigationController?.pushViewController(self.quickLookController, animated: true)
}
我希望它始终是第二种颜色,无论它是否是我第一次调用qlviewcontroller
。每当应用程序终止并重新启动时,它就会切换回粉红色
编辑(2/12/19)
我已经解决了。它不起作用的原因是,在将QLPreviewController
推送到navigationController
堆栈之前,我正在设置tintColor,因此,它正在为堆栈中的上一个navigationItem设置tintColor
(这算不了什么,因为我在整个应用程序中使用了自定义的导航栏
)。因此,当QLPreviewController
从堆栈中弹出,然后在下次打开文档时推回时,tintColor
仍保留在我上次设置它时的状态
func openQLPreview() {
quickLookController = QLPreviewController()
quickLookController.dataSource = self
self.navigationController?.pushViewController(self.quickLookController, animated: true)
UINavigationBar.appearance().tintColor = UIColor.hexStringToUIColor(hexStr: "202020")
}
因此,只需使用UINavigationBar.appearance().tintColor
在推送qlviewController
后设置tintColor,即可解决此问题。尝试此操作
@IBOutlet weak var m_NavBar: UINavigationBar!
func openQLPreview()
{
quickLookController = QLPreviewController()
m_NavBar.appearance().tintColor = UIColor.hexStringToUIColor(hexStr: "202020")
quickLookController.dataSource = self
self.navigationController?.pushViewController(self.quickLookController, animated: true)
}
我没有将IB用于QLPreviewController或导航栏;tt是以编程方式完成的。