CPDFBookmarkViewCell.swift 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // CPDFBookmarkViewCell.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 CPDFBookmarkViewCell: UITableViewCell {
  14. var titleLabel: UILabel?
  15. var pageIndexLabel: UILabel?
  16. var moreButton: UIButton?
  17. var deleteButton: UIButton?
  18. var editButton: UIButton?
  19. private var bottomView: UIView?
  20. override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  21. super.init(style: style, reuseIdentifier: reuseIdentifier)
  22. titleLabel = UILabel(frame: CGRect(x: 15, y: 5, width: self.bounds.size.width - 110, height: self.bounds.size.height - 10))
  23. titleLabel!.autoresizingMask = [.flexibleWidth, .flexibleHeight]
  24. pageIndexLabel = UILabel(frame: CGRect(x: self.bounds.size.width - 100, y: 5, width: 85, height: self.bounds.size.height - 10))
  25. pageIndexLabel!.textAlignment = .right
  26. pageIndexLabel!.autoresizingMask = [.flexibleLeftMargin, .flexibleHeight]
  27. bottomView = UIView(frame: CGRect(x: 0, y: self.bounds.size.height - 1, width: self.bounds.size.width, height: 1))
  28. bottomView!.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.1)
  29. bottomView!.autoresizingMask = .flexibleWidth
  30. self.contentView.addSubview(titleLabel!)
  31. self.contentView.addSubview(pageIndexLabel!)
  32. self.contentView.addSubview(bottomView!)
  33. }
  34. required init?(coder aDecoder: NSCoder) {
  35. super.init(coder: aDecoder)
  36. // Initialization code
  37. }
  38. override func setSelected(_ selected: Bool, animated: Bool) {
  39. super.setSelected(selected, animated: animated)
  40. // Configure the view for the selected state
  41. }
  42. // MARK: - Action
  43. @objc func buttonItemClicked_edit(sender: Any) {
  44. if let tableView = getTableView() {
  45. if let indexPath = tableView.indexPath(for: self) {
  46. tableView.setEditing(true, animated: true)
  47. tableView.selectRow(at: indexPath, animated: true, scrollPosition: .middle)
  48. }
  49. }
  50. }
  51. func getTableView() -> UITableView? {
  52. var tableView = self.superview
  53. while !(tableView is UITableView) && tableView != nil {
  54. tableView = tableView?.superview
  55. }
  56. return tableView as? UITableView
  57. }
  58. }