ZLImageNavController.swift 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // ZLImageNavController.swift
  3. // ZLPhotoBrowser
  4. //
  5. // Created by long on 2020/8/18.
  6. //
  7. // Copyright (c) 2020 Long Zhang <495181165@qq.com>
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining a copy
  10. // of this software and associated documentation files (the "Software"), to deal
  11. // in the Software without restriction, including without limitation the rights
  12. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. // copies of the Software, and to permit persons to whom the Software is
  14. // furnished to do so, subject to the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be included in
  17. // all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. // THE SOFTWARE.
  26. import UIKit
  27. import Photos
  28. class ZLImageNavController: UINavigationController {
  29. var isSelectedOriginal: Bool = false
  30. var arrSelectedModels: [ZLPhotoModel] = []
  31. var selectImageBlock: ( () -> Void )?
  32. var cancelBlock: ( () -> Void )?
  33. deinit {
  34. zl_debugPrint("ZLImageNavController deinit")
  35. }
  36. override var preferredStatusBarStyle: UIStatusBarStyle {
  37. return ZLPhotoConfiguration.default().statusBarStyle
  38. }
  39. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  40. super.init(nibName: nil, bundle: nil)
  41. }
  42. override init(rootViewController: UIViewController) {
  43. super.init(rootViewController: rootViewController)
  44. self.navigationBar.barStyle = .black
  45. self.navigationBar.isTranslucent = true
  46. self.modalPresentationStyle = .fullScreen
  47. self.isNavigationBarHidden = true
  48. let colorDeploy = ZLPhotoConfiguration.default().themeColorDeploy
  49. self.navigationBar.setBackgroundImage(self.image(color: colorDeploy.navBarColor), for: .default)
  50. self.navigationBar.tintColor = colorDeploy.navTitleColor
  51. self.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: colorDeploy.navTitleColor]
  52. }
  53. required init?(coder aDecoder: NSCoder) {
  54. fatalError("init(coder:) has not been implemented")
  55. }
  56. override func viewDidLoad() {
  57. super.viewDidLoad()
  58. // Do any additional setup after loading the view.
  59. }
  60. func image(color: UIColor) -> UIImage? {
  61. let rect = CGRect(x: 0, y: 0, width: 1, height: 1)
  62. UIGraphicsBeginImageContext(rect.size)
  63. let context = UIGraphicsGetCurrentContext()
  64. context?.setFillColor(color.cgColor)
  65. context?.fill(rect)
  66. let image = UIGraphicsGetImageFromCurrentImageContext()
  67. UIGraphicsEndImageContext()
  68. return image
  69. }
  70. }