Skip to content

Instantly share code, notes, and snippets.

@amixpal
Created December 2, 2019 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amixpal/88e8872f765be9a64969e96b36abe85b to your computer and use it in GitHub Desktop.
Save amixpal/88e8872f765be9a64969e96b36abe85b to your computer and use it in GitHub Desktop.
//
// PdfViewController.swift
// Fitme
//
// Created by paly on 9/9/19.
// Copyright © 2019 Paly. All rights reserved.
//
import UIKit
import PDFKit
class PdfViewController: UIViewController {
@IBOutlet var pdfView: PDFView!
var pdfUrl: String!
override func viewDidLoad() {
super.viewDidLoad()
initUI()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.setNavigationBarHidden(false , animated: false)
let button = UIButton(type: .custom)
self.navigationController?.navigationBar.barTintColor = UIColor.white
button.setImage(UIImage(named: "ic_back_new"), for: .normal)
button.addTarget(self, action: #selector(backButton(_:)), for: .touchUpInside)
button.frame = CGRect.init(x: 0, y: 0, width: 30, height: 30)
let barButton = UIBarButtonItem(customView: button)
self.navigationItem.leftBarButtonItem = barButton
self.navigationItem.title = "Detail"
UINavigationBar.appearance().titleTextAttributes = [.foregroundColor : UIColor.darkGray]
self.navigationController?.navigationBar.clipsToBounds = false
self.navigationController?.navigationBar.shadowImage = UIColor(red: 215/255, green: 215/255, blue: 215/255, alpha: 1.0).image(CGSize(width: self.view.frame.width, height: 1))
}
@objc private func backButton(_ sender: UIBarButtonItem) {
self.navigationController?.popViewController(animated: true)
self.dismiss(animated: true, completion: nil)
}
func initUI(){
let url = URL(string: self.pdfUrl)
if let document = PDFDocument(url: url!) {
pdfView.autoScales = true
pdfView.displayMode = .singlePageContinuous
pdfView.displayDirection = .vertical
pdfView.document = document
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment