Alua-Kinzhebayeva / iOS-PDF-Reader

PDF Reader for iOS written in Swift
MIT License
533 stars 150 forks source link

Adding a back button without using a nav controller? #63

Open jackdem opened 7 years ago

jackdem commented 7 years ago

I use

present(readerController, animated: true, completion: nil)

rather than a nav controller to present the view. Is it possible to have a way to add a close button to the view programmatically?

ranunez commented 6 years ago

Its possible, the app should detect when its being presented in a modal, and if so, it should have some sort of close button to dismiss. Great idea!

JorgeAGomez commented 6 years ago

I found a solution for this:

// Create a back button programmatically - the goBackTapped function just dismiss the viewcontroller. let myBackButton = UIBarButtonItem(title: "Cancel", style: .done, target: self, action: #selector(self.goBackTapped(_:)))

//create the document let document = PDFDocument(fileData: pdf_data, fileName: "contract_pdf")

//load the PDFViewController let readerController = PDFViewController.createNew(with: document!, title: "Contract", backButton: myBackButton)

//Create a UINaviagationController and pass the readerController you just created let targetNavigationController = UINavigationController(rootViewController: readerController)

// Present the NavitationController self.present(targetNavigationController, animated: true, completion: nil)

Hope this help :)

ranunez commented 6 years ago

Thanks for the code snippets, can you please provide a pull request?