Laying white toolbar over QLPreviewController tool

2019-07-31 00:43发布

I stumbled upon this SO discussion on adding/removing qlpreviewcontroller's uibarbuttonitems. However they were removing the navigation bar and overlaying a new one on top of it.

I was looking to change the toolbar primarily because the toolbar that comes with QLPreviewController is black and the rest of the toolbars in my application are white.

I have code in place to get the bar overlaying but it seems that when I set the toolbar tint color to white, its actually becoming a light gray. I was thinking that this was because the toolbar was not opaque but after setting alpha to 1.0 it still looks the same.

Relevant toolbar code from class extending QLPreviewController

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    ....

    self.overlayToolBar?.setItems([actionBtn], animated: false)
    self.overlayToolBar?.tintColor = .blue
    self.overlayToolBar?.barTintColor = .white
}

Toolbar from previous screen

enter image description here

Toolbar from QLPreviewController screen

enter image description here

Original Toolbar for QLPreviewController

enter image description here

Is there a different/better way to set the toolbar color? Since QuickLook runs through XPC I can't edit the toolbar directly. Thus I have to do this roundabout hack to get a customized toolbar on the screen.

1条回答
smile是对你的礼貌
2楼-- · 2019-07-31 01:05

I ran into a similar issue when I was attempting to not show all of the items on a QLPreviewController.

I ended up subclassing the QLPreviewController:

import QuickLook

class PreviewController: QLPreviewController {

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)

        navigationItem.leftBarButtonItems = nil
    }

}
查看更多
登录 后发表回答