1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- import UIKit
- public protocol NCViewCertificateDetailsDelegate {
- func viewCertificateDetailsDismiss(host: String)
- }
- public extension NCViewCertificateDetailsDelegate {
- func viewCertificateDetailsDismiss(host: String) {}
- }
- class NCViewCertificateDetails: UIViewController {
- @IBOutlet weak var buttonCancel: UIBarButtonItem!
- @IBOutlet weak var scrollView: UIScrollView!
- @IBOutlet weak var textView: UITextView!
- private let directoryCertificate = CCUtility.getDirectoryCerificates()!
- public var delegate: NCViewCertificateDetailsDelegate?
- @objc public var host: String = ""
-
- override func viewDidLoad() {
- super.viewDidLoad()
- self.navigationItem.title = NSLocalizedString("_certificate_details_", comment: "")
- buttonCancel.title = NSLocalizedString("_close_", comment: "")
- let certNamePathTXT = directoryCertificate + "/" + host + ".txt"
- if FileManager.default.fileExists(atPath: certNamePathTXT) {
- do {
- let text = try String(contentsOfFile: certNamePathTXT, encoding: .utf8)
- let font = UIFont.systemFont(ofSize: 13)
- let attributes = [NSAttributedString.Key.font: font] as [NSAttributedString.Key: Any]
- var contentRect = NSString(string: text).boundingRect(with: CGSize(width: CGFloat.greatestFiniteMagnitude, height: 0), options: NSStringDrawingOptions.usesLineFragmentOrigin, attributes: attributes, context: nil)
- contentRect = CGRect(x: contentRect.origin.x, y: contentRect.origin.y, width: ceil(contentRect.size.width), height: ceil(contentRect.size.height))
- var contentWidth = contentRect.size.width
- if contentWidth < view.frame.size.width {
- contentWidth = view.frame.size.width
- }
- var contentHeight = contentRect.size.height
- if contentHeight < view.frame.size.height {
- contentHeight = view.frame.size.width
- }
- textView.frame = CGRect(x: 0, y: 0, width: contentWidth, height: contentHeight)
- textView.font = font
- textView.text = text
- scrollView.contentSize = contentRect.size
- scrollView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 50, right: 0)
- } catch {
- print("error")
- }
- } else {
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
- self.dismiss(animated: true, completion: nil)
- }
- }
- }
- override func viewWillDisappear(_ animated: Bool) {
- super.viewWillDisappear(animated)
-
- self.delegate?.viewCertificateDetailsDismiss(host: host)
- }
-
- @IBAction func actionCancel(_ sender: UIBarButtonItem) {
- self.dismiss(animated: true, completion: nil)
- }
- }
|