如何对QLPreviewController和禁用共享按钮进行子类化?

时间:2017-09-23 05:26:21

标签: ios swift qlpreviewcontroller

  • 我已经完成了这样的代码,但是它打开了QLPreviewController但是 共享按钮未被禁用。我尝试了不同的东西,但它已经尝试过了 没工作。

    - 或者你可以建议我任何不同的预览控制器,我可以在其中禁用分享按钮。

  • qlViewController = QLPreviewController()

  • qlViewController.navigationItem.rightBarButtonItem = nil

  • qlViewController.delegate = self
  • qlViewController.dataSource = self

func numberOfPreviewItemsInPreviewController(controller:QLPreviewController) - > Int {         返回1     }

func previewController(controller: QLPreviewController, previewItemAtIndex index: Int) -> QLPreviewItem {
    controller.navigationItem.rightBarButtonItem = nil
    return fileUrlToOpen
}

1 个答案:

答案 0 :(得分:0)

有一个示例如何隐藏右侧分享按钮

final class AttachmentQuickLookVC: QLPreviewController {

    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        self.navigationItem.rightBarButtonItems = [UIBarButtonItem]()        
    }
}

此外,如果你想自定义后退按钮,你可以做这样的事情:

final class AttachmentQuickLookVC: QLPreviewController {

    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()        
        let backButton = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 35))

        backButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
        backButton.contentHorizontalAlignment = .left
        backButton.setImage(UIImage(named: "ic_back"), for: .normal)

        let barButton = UIBarButtonItem(customView: backButton)
        self.navigationItem.leftBarButtonItems = [barButton]
        self.navigationItem.hidesBackButton = true
    }
}