QLPreviewController的tintColor首次打开时是不同的

时间:2019-12-02 08:32:26

标签: ios swift user-interface uinavigationbar qlpreviewcontroller

每当我提起tintColor时,QLPreviewController默认是粉红色的。我希望它是一种特定的颜色,所以我将其设置为

UINavigationBar.appearance().tintColor = UIColor.hexStringToUIColor(hexStr: "202020")

这就是显示QLPreviewController的方法的样子

func openQLPreview() {
    quickLookController = QLPreviewController()
    UINavigationBar.appearance().tintColor = UIColor.hexStringToUIColor(hexStr: "202020")
    quickLookController.dataSource = self
    self.navigationController?.pushViewController(self.quickLookController, animated: true)
}

This is what it looks like the first time (after installing or closing and re-opening I open a document using the QLPreviewController

And this is what it looks like when I tap the back arrow and open the same document or any other document

无论我是否第一次打电话给QLPreviewController,我都希望它一直是第二种颜色。每当应用终止并重新启动时,它就会切换回粉红色。

编辑(19/12/12) 我已经解决了。之所以不起作用,是因为我在将QLPreviewController推入navigationController堆栈之前设置了tintColor,因此,它正在为堆栈中的上一个NavigationItem设置tintColor(之所以没什么,是因为我在整个应用中都使用了自定义navigationBar。因此,当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之后使用QLPreviewController设置tintColor即可解决此问题。

1 个答案:

答案 0 :(得分:0)

尝试

@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)
}