SwiftModalWebVC.swift 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // SwiftModalWebVC.swift
  3. //
  4. // Created by Myles Ringle on 24/06/2015.
  5. // Transcribed from code used in SVWebViewController.
  6. // Copyright (c) 2015 Myles Ringle & Oliver Letterer. All rights reserved.
  7. //
  8. import UIKit
  9. public class SwiftModalWebVC: UINavigationController {
  10. public enum SwiftModalWebVCTheme {
  11. case lightBlue, lightBlack, dark
  12. }
  13. weak var webViewDelegate: UIWebViewDelegate? = nil
  14. public convenience init(urlString: String) {
  15. self.init(pageURL: URL(string: urlString)!)
  16. }
  17. public convenience init(urlString: String, theme: SwiftModalWebVCTheme) {
  18. self.init(pageURL: URL(string: urlString)!, theme: theme)
  19. }
  20. public convenience init(pageURL: URL) {
  21. self.init(request: URLRequest(url: pageURL))
  22. }
  23. public convenience init(pageURL: URL, theme: SwiftModalWebVCTheme) {
  24. self.init(request: URLRequest(url: pageURL), theme: theme)
  25. }
  26. public init(request: URLRequest, theme: SwiftModalWebVCTheme = .dark) {
  27. let webViewController = SwiftWebVC(aRequest: request)
  28. webViewController.storedStatusColor = UINavigationBar.appearance().barStyle
  29. let doneButton = UIBarButtonItem(image: SwiftWebVC.bundledImage(named: "SwiftWebVCDismiss"),
  30. style: UIBarButtonItemStyle.plain,
  31. target: webViewController,
  32. action: #selector(SwiftWebVC.doneButtonTapped))
  33. switch theme {
  34. case .lightBlue:
  35. doneButton.tintColor = nil
  36. webViewController.buttonColor = nil
  37. webViewController.titleColor = UIColor.black
  38. UINavigationBar.appearance().barStyle = UIBarStyle.default
  39. case .lightBlack:
  40. doneButton.tintColor = UIColor.darkGray
  41. webViewController.buttonColor = UIColor.darkGray
  42. webViewController.titleColor = UIColor.black
  43. UINavigationBar.appearance().barStyle = UIBarStyle.default
  44. case .dark:
  45. doneButton.tintColor = UIColor.white
  46. webViewController.buttonColor = UIColor.white
  47. webViewController.titleColor = UIColor.groupTableViewBackground
  48. UINavigationBar.appearance().barStyle = UIBarStyle.black
  49. }
  50. if (UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad) {
  51. webViewController.navigationItem.leftBarButtonItem = doneButton
  52. }
  53. else {
  54. webViewController.navigationItem.rightBarButtonItem = doneButton
  55. }
  56. super.init(rootViewController: webViewController)
  57. }
  58. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  59. super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
  60. }
  61. required public init(coder aDecoder: NSCoder) {
  62. fatalError("init(coder:) has not been implemented")
  63. }
  64. override public func viewWillAppear(_ animated: Bool) {
  65. super.viewWillAppear(false)
  66. }
  67. }