CCustomizeStampTableViewCell.swift 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // CCustomizeStampTableViewCell.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. @objc protocol CCustomizeStampTableViewCellDelegate: AnyObject {
  14. @objc optional func customizeStampTableViewCell(_ customizeStampTableViewCell: CCustomizeStampTableViewCell)
  15. }
  16. class CCustomizeStampTableViewCell: UITableViewCell {
  17. var customizeStampImageView: UIImageView?
  18. weak var deleteDelegate: CCustomizeStampTableViewCellDelegate?
  19. private var deleteButton: UIButton?
  20. // MARK: - Initializers
  21. override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  22. super.init(style: style, reuseIdentifier: reuseIdentifier)
  23. self.customizeStampImageView = UIImageView()
  24. if customizeStampImageView != nil {
  25. self.contentView.addSubview(self.customizeStampImageView!)
  26. }
  27. self.deleteButton = UIButton()
  28. self.deleteButton?.setImage(UIImage(named: "CPDFSignatureImageDelete", in: Bundle(for: self.classForCoder), compatibleWith: nil), for: .normal)
  29. self.deleteButton?.addTarget(self, action: #selector(buttonItemClicked_delete(_:)), for: .touchUpInside)
  30. if deleteButton != nil {
  31. self.contentView.addSubview(self.deleteButton!)
  32. }
  33. self.backgroundColor = CPDFColorUtils.CAnnotationPropertyViewControllerBackgoundColor()
  34. }
  35. required init?(coder: NSCoder) {
  36. fatalError("init(coder:) has not been implemented")
  37. }
  38. override func layoutSubviews() {
  39. super.layoutSubviews()
  40. let height = self.contentView.bounds.size.height - 10
  41. var width = height * ((self.customizeStampImageView?.image?.size.width ?? 1.0) / (self.customizeStampImageView?.image?.size.height ?? 1.0))
  42. width = min(width, self.contentView.bounds.size.width - 80.0)
  43. self.customizeStampImageView?.frame = CGRect(x: (self.bounds.size.width - width) / 2.0, y: 5.0, width: width, height: height)
  44. self.customizeStampImageView?.center = self.contentView.center
  45. self.deleteButton?.frame = CGRect(x: self.bounds.size.width - 50, y: 0.0, width: 50, height: 50)
  46. }
  47. // MARK: - Action
  48. @objc func buttonItemClicked_delete(_ button: UIButton) {
  49. deleteDelegate?.customizeStampTableViewCell?(self)
  50. }
  51. }