CPDFDisplayTableViewCell.swift 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // CPDFDisplayTableViewCell.swift
  3. // ComPDFKit_Tools
  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. class CPDFDisplayTableViewCell: UITableViewCell {
  14. var checkImageView: UIImageView?
  15. var iconImageView: UIImageView?
  16. var titleLabel: UILabel?
  17. var modeSwitch: UISwitch?
  18. var switchBlock: (() -> Void)?
  19. var hiddenSplitView: Bool = false
  20. private var splitView: UIView?
  21. override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  22. super.init(style: style, reuseIdentifier: reuseIdentifier)
  23. modeSwitch = UISwitch()
  24. modeSwitch?.isHidden = true
  25. modeSwitch?.transform = CGAffineTransform(scaleX: 0.75, y: 0.75)
  26. modeSwitch?.sizeToFit()
  27. modeSwitch?.addTarget(self, action: #selector(switchAction(_:)), for: .valueChanged)
  28. if modeSwitch != nil {
  29. contentView.addSubview(modeSwitch!)
  30. }
  31. checkImageView = UIImageView()
  32. checkImageView?.image = UIImage(named: "CDisplayImageNameCheck", in: Bundle(for: type(of: self)), compatibleWith: nil)
  33. checkImageView?.isHidden = true
  34. if checkImageView != nil {
  35. contentView.addSubview(checkImageView!)
  36. }
  37. iconImageView = UIImageView()
  38. if iconImageView != nil {
  39. contentView.addSubview(iconImageView!)
  40. }
  41. titleLabel = UILabel()
  42. titleLabel?.font = UIFont.systemFont(ofSize: 17)
  43. if titleLabel != nil {
  44. contentView.addSubview(titleLabel!)
  45. }
  46. splitView = UIView()
  47. splitView?.backgroundColor = CPDFColorUtils.CTableviewCellSplitColor()
  48. if splitView != nil {
  49. contentView.addSubview(splitView!)
  50. }
  51. }
  52. required init?(coder aDecoder: NSCoder) {
  53. fatalError("init(coder:) has not been implemented")
  54. }
  55. override func layoutSubviews() {
  56. super.layoutSubviews()
  57. modeSwitch?.frame = CGRect(x: contentView.frame.size.width - 50, y: (contentView.frame.size.height - 25)/2, width: 30, height: 40)
  58. checkImageView?.frame = CGRect(x: contentView.frame.size.width - 40, y: (contentView.frame.size.height - 30)/2, width: 30, height: 30)
  59. iconImageView?.frame = CGRect(x: 20, y: 12, width: 20, height: 20)
  60. let width = contentView.frame.size.width - (modeSwitch?.frame.size.width ?? 0) - 40 - (iconImageView?.frame.size.width ?? 0)
  61. titleLabel?.frame = CGRect(x: (iconImageView?.frame.maxX ?? 0) + 10, y: 12, width: width, height: 20)
  62. splitView?.frame = CGRect(x: 0, y: contentView.frame.size.height-1, width: contentView.frame.size.width, height: 1)
  63. }
  64. // MARK: - Action
  65. @objc func switchAction(_ sender: UISwitch) {
  66. if let switchBlock = switchBlock {
  67. switchBlock()
  68. }
  69. }
  70. func setHiddenSplitView(_ hiddenSplitView: Bool) {
  71. self.hiddenSplitView = hiddenSplitView
  72. splitView!.isHidden = hiddenSplitView
  73. }
  74. }