//
//  PreviewController.swift
//  MobilePortal
//
//  Created by caiyang on 2021/2/8.
//  Copyright © 2021 yin chen. All rights reserved.
//

import UIKit
import QuickLook
class PreviewController: QLPreviewController,QLPreviewControllerDelegate,QLPreviewControllerDataSource {
    
    var fileUrlList = NSMutableArray()
    
    func loadUrlPath(fileUrl:NSURL?){
        if PreviewController.canPreview(fileUrl!) {
            self.fileUrlList.add(fileUrl!)
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.delegate = self
        self.dataSource = self
        defaultBackButtonItem()
        initReturnBtn()
    }
    private func defaultBackButtonItem(){
        self.wr_setNavBarBarTintColor(UIColor.white)
        self.wr_setNavBarTitleColor(UIColorFromRGB(rgbValue: 0x23262A))
        self.wr_setNavBarTintColor(UIColorFromRGB(rgbValue: 0x666666))
    }
    //左侧返回按钮
    func initReturnBtn(){
        let leftN:UIBarButtonItem = UIBarButtonItem.init(image: UIImage.init(named: "return_image")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(arrowResponse))
        self.navigationItem.leftBarButtonItem = leftN
//        self.navigationItem.leftBarButtonItem?.title = "取消"
    }
    @objc func arrowResponse() {
//        self.navigationController?.popViewController(animated: true)
        self.dismiss(animated: true) {
            
        }
    }
    func numberOfPreviewItems(in controller: QLPreviewController) -> Int {
        return self.fileUrlList.count
    }
    
    func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
        return self.fileUrlList[index] as! QLPreviewItem
    }
    

}
