0
votes

I need to hide the share button button from QLPreviewController

this is the original code to show PDF (for example) into new view

var previewItem = NSURL()
func preview(_command: CDVInvokedUrlCommand){
 self.previewItem = fileLocationURL! as NSURL
 let previewController = QLPreviewController();
 previewController.dataSource = self;
 self.viewController?.present(previewController, animated: true, completion: nil);
}
extension PreviewAnyFile: QLPreviewControllerDataSource {
    func numberOfPreviewItems(in controller: QLPreviewController) -> Int {
        return 1
    }

    func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
        return self.previewItem as QLPreviewItem
    }
}

developers need to remove share button

i tried this code (superclass the QLPreviewController into QLSPreviewController ) but the share button still exist

class QLSPreviewController : QLPreviewController {
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    }
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(true )
        //This hides the share item
        if let add =  self.children.first as? UINavigationController {
            if let layoutContainerView  = add.view.subviews[1] as? UINavigationBar {
                 layoutContainerView.subviews[2].subviews[1].isHidden = true
            }
        }
    }
}
1
Do you have access to modify the source of the QLSPreviewController?flanker
To create a custom PDF viewer you should subclass PDFViewLeo Dabus
@flanker yes I have,Mostafa King

1 Answers

0
votes

Based on a couple of reasonably safe assumptions:

  • that your PDF viewer class is subclassed from a UIViewController
  • the navigationBar comes from a navigation controller and isn't manually created

you should just be able to remove the UBarButtonItem

from inside ViewDidLoad:

navigationItem.rightBarButtonItems = []

or from outside the class if needs be:

myPDFViewController.navigationItem.rightBarButtonItems = []