CLocationSelectView.swift 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // CLocationSelectView.swift
  3. // PDFViewer-Swift
  4. //
  5. // Copyright © 2014-2024 PDF Technologies, Inc. All Rights Reserved.
  6. //
  7. // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  8. // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  9. // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  10. // This notice may not be removed from this file.
  11. //
  12. import UIKit
  13. @objc protocol CLocationSelectViewDelegate: AnyObject {
  14. @objc optional func locationSelectView(_ locationSelectView: CLocationSelectView, isFront: Bool)
  15. }
  16. class CLocationSelectView: UIView {
  17. weak var delegate: CLocationSelectViewDelegate?
  18. private var titleLabel: UILabel?
  19. private var topButton: UIButton?
  20. private var bottomButton: UIButton?
  21. // MARK: - Initializers
  22. override init(frame: CGRect) {
  23. super.init(frame: frame)
  24. titleLabel = UILabel()
  25. titleLabel?.autoresizingMask = .flexibleRightMargin
  26. titleLabel?.text = NSLocalizedString("Layout Options", comment: "")
  27. titleLabel?.textColor = .gray
  28. titleLabel?.font = UIFont.systemFont(ofSize: 12.0)
  29. if titleLabel != nil {
  30. addSubview(titleLabel!)
  31. }
  32. topButton = UIButton()
  33. topButton?.setImage(UIImage(named: "CLocationSelectTopImage", in: Bundle(for: self.classForCoder), compatibleWith: nil), for: .normal)
  34. topButton?.addTarget(self, action: #selector(buttonItemClicked_Top), for: .touchUpInside)
  35. if topButton != nil {
  36. addSubview(self.topButton!)
  37. }
  38. bottomButton = UIButton()
  39. bottomButton?.setImage(UIImage(named: "CLocationSelectBottomImage", in: Bundle(for: self.classForCoder), compatibleWith: nil), for: .normal)
  40. bottomButton?.addTarget(self, action: #selector(buttonItemClicked_Bottom), for: .touchUpInside)
  41. if bottomButton != nil {
  42. addSubview(self.bottomButton!)
  43. }
  44. }
  45. required init?(coder: NSCoder) {
  46. fatalError("init(coder:) has not been implemented")
  47. }
  48. override func layoutSubviews() {
  49. super.layoutSubviews()
  50. titleLabel?.frame = CGRect(x: 20, y: 0, width: 200, height: 30)
  51. topButton?.frame = CGRect(x: bounds.size.width - 65, y: 0, width: 45, height: 30)
  52. bottomButton?.frame = CGRect(x: bounds.size.width - 110, y: 0, width: 45, height: 30)
  53. }
  54. // MARK: - Action
  55. @objc func buttonItemClicked_Top(_ sender: UIButton) {
  56. topButton?.backgroundColor = CPDFColorUtils.CAnnotationBarNoSelectBackgroundColor()
  57. bottomButton?.backgroundColor = CPDFColorUtils.CAnnotationBarNoSelectBackgroundColor()
  58. topButton?.backgroundColor = CPDFColorUtils.CAnnotationBarSelectBackgroundColor()
  59. delegate?.locationSelectView?(self, isFront: true)
  60. }
  61. @objc func buttonItemClicked_Bottom(_ sender: UIButton) {
  62. topButton?.backgroundColor = CPDFColorUtils.CAnnotationBarNoSelectBackgroundColor()
  63. bottomButton?.backgroundColor = CPDFColorUtils.CAnnotationBarNoSelectBackgroundColor()
  64. bottomButton?.backgroundColor = CPDFColorUtils.CAnnotationBarSelectBackgroundColor()
  65. delegate?.locationSelectView?(self, isFront: false)
  66. }
  67. func setLocation(_ isFront: Bool) {
  68. topButton?.backgroundColor = CPDFColorUtils.CAnnotationBarNoSelectBackgroundColor()
  69. bottomButton?.backgroundColor = CPDFColorUtils.CAnnotationBarNoSelectBackgroundColor()
  70. if isFront {
  71. topButton?.backgroundColor = CPDFColorUtils.CAnnotationBarSelectBackgroundColor()
  72. } else {
  73. bottomButton?.backgroundColor = CPDFColorUtils.CAnnotationBarSelectBackgroundColor()
  74. }
  75. }
  76. }