How to Disable QLPreviewController print Button

Viewed 14059

Can anyone tell me how to remove the QLPreviewController print button? Also would like to disable cut/paste/copy.

9 Answers

this work for me . you have to debugg child navigation controller

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.childViewControllers.first as? UINavigationController {
            if let layoutContainerView  = add.view.subviews[1] as? UINavigationBar {
                 layoutContainerView.subviews[2].subviews[1].isHidden = true
            }
        }
    }
}

This subclass works with Swift 4.2 and iOS 12. It uses a trick to make sure that the share icon is hidden without flashing in the eyes of the user.

import QuickLook
import UIKit

class PreviewController: QLPreviewController {
    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(true)
        guard let layoutContainerView = self.children.first?.view.subviews[1] as? UINavigationBar else { return }
        layoutContainerView.isHidden = true
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(true)
        guard let layoutContainerView = self.children.first?.view.subviews[1] as? UINavigationBar else { return }
        layoutContainerView.subviews[2].subviews[1].isHidden = true
        layoutContainerView.isHidden = false
    }
}

I resolved the same issue with:

let previewVC = QLPreviewController()

override func viewDidLoad() {

    super.viewDidLoad()

    previewVC.navigationItem.rightBarButtonItem = UIBarButtonItem()
}
Related