3
votes
  • I have done code like this but it's open QLPreviewController but Share button was not disabled. I have tried different things but it's not worked.

    - Or You Can Suggest me any different Preview Controller in which i can Disable Share button.

  • qlViewController = QLPreviewController()

  • qlViewController.navigationItem.rightBarButtonItem = nil

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

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

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

1 Answers

-1
votes

There is an example how to hide right share button

final class AttachmentQuickLookVC: QLPreviewController {

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

Also, u can do something like this if u want to customize back button:

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