CPDFSignatureViewCell.swift 2.4 KB

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