CTileSelectView.swift 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // CTileSelectView.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 CTileSelectViewDelegate: AnyObject {
  14. @objc optional func tileSelectView(_ tileSelectView: CTileSelectView, isTile: Bool)
  15. }
  16. class CTileSelectView: UIView {
  17. weak var delegate: CTileSelectViewDelegate?
  18. private var titleLabel: UILabel?
  19. var tileSwitch: UISwitch?
  20. // MARK: - Initializers
  21. override init(frame: CGRect) {
  22. super.init(frame: frame)
  23. titleLabel = UILabel()
  24. titleLabel?.autoresizingMask = .flexibleRightMargin
  25. titleLabel?.text = NSLocalizedString("Tile", comment: "")
  26. titleLabel?.textColor = .gray
  27. titleLabel?.font = UIFont.systemFont(ofSize: 12.0)
  28. if titleLabel != nil {
  29. addSubview(titleLabel!)
  30. }
  31. tileSwitch = UISwitch()
  32. tileSwitch?.addTarget(self, action: #selector(switchItemClicked_Top(_ :)), for: .valueChanged)
  33. if tileSwitch != nil {
  34. addSubview(tileSwitch!)
  35. }
  36. }
  37. required init?(coder: NSCoder) {
  38. fatalError("init(coder:) has not been implemented")
  39. }
  40. override func layoutSubviews() {
  41. super.layoutSubviews()
  42. titleLabel?.frame = CGRect(x: 20, y: 0, width: 200, height: 45)
  43. tileSwitch?.frame = CGRect(x: bounds.size.width - 80, y: 0, width: 60, height: 45)
  44. }
  45. // MARK: - Action
  46. @objc func switchItemClicked_Top(_ sender: UISwitch) {
  47. delegate?.tileSelectView?(self, isTile: sender.isOn)
  48. }
  49. }