StampCollectionHeaderView1.swift 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // StampCollectionHeaderView1.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 StampHeaderViewDelegate: AnyObject {
  14. @objc optional func addText(with headerView: StampCollectionHeaderView1)
  15. @objc optional func addImage(with headerView: StampCollectionHeaderView1)
  16. }
  17. class StampCollectionHeaderView1: UICollectionReusableView {
  18. var textLabel: UILabel?
  19. weak var delegate: StampHeaderViewDelegate?
  20. private var headerView: UIView?
  21. private var textButton: UIButton?
  22. private var imageButton: UIButton?
  23. override init(frame: CGRect) {
  24. super.init(frame: frame)
  25. headerView = UIView()
  26. headerView?.backgroundColor = UIColor.clear
  27. if headerView != nil {
  28. addSubview(headerView!)
  29. }
  30. textButton = UIButton(type: .system)
  31. textButton?.setTitle(NSLocalizedString("New Text Stamp", comment: ""), for: .normal)
  32. textButton?.setTitleColor(UIColor(red: 36.0/255.0, green: 36.0/255.0, blue: 36.0/255.0, alpha: 1.0), for: .normal)
  33. textButton?.addTarget(self, action: #selector(buttonItemClicked_AddText(_ :)), for: .touchUpInside)
  34. textButton?.layer.borderWidth = 1
  35. textButton?.layer.cornerRadius = 5
  36. textButton?.titleLabel?.font = UIFont.systemFont(ofSize: 16.0)
  37. textButton?.titleLabel?.adjustsFontSizeToFitWidth = true
  38. textButton?.layer.borderColor = UIColor(red: 17.0/255.0, green: 140.0/255.0, blue: 1.0, alpha: 1.0).cgColor
  39. if textButton != nil {
  40. headerView?.addSubview(textButton!)
  41. }
  42. imageButton = UIButton(type: .system)
  43. imageButton?.setTitle(NSLocalizedString("New Image Stamp", comment: ""), for: .normal)
  44. imageButton?.setTitleColor(UIColor(red: 36.0/255.0, green: 36.0/255.0, blue: 36.0/255.0, alpha: 1.0), for: .normal)
  45. imageButton?.titleLabel?.font = UIFont.systemFont(ofSize: 16.0)
  46. imageButton?.titleLabel?.adjustsFontSizeToFitWidth = true
  47. imageButton?.addTarget(self, action: #selector(buttonItemClicked_AddImage(_ :)), for: .touchUpInside)
  48. imageButton?.layer.borderWidth = 1
  49. imageButton?.layer.cornerRadius = 5
  50. imageButton?.layer.borderColor = UIColor(red: 17.0/255.0, green: 140.0/255.0, blue: 1.0, alpha: 1.0).cgColor
  51. if imageButton != nil {
  52. headerView?.addSubview(imageButton!)
  53. }
  54. backgroundColor = UIColor(red: 248.0/255.0, green: 248.0/255.0, blue: 248.0/255.0, alpha: 1.0)
  55. textLabel = UILabel()
  56. textLabel?.textColor = UIColor(red: 36.0/255.0, green: 36.0/255.0, blue: 36.0/255.0, alpha: 1.0)
  57. textLabel?.font = UIFont.systemFont(ofSize: 14.0)
  58. if textLabel != nil {
  59. addSubview(textLabel!)
  60. }
  61. }
  62. required init?(coder aDecoder: NSCoder) {
  63. fatalError("init(coder:) has not been implemented")
  64. }
  65. override func layoutSubviews() {
  66. super.layoutSubviews()
  67. headerView?.frame = CGRect(x: 0, y: 0, width: bounds.size.width, height: 80)
  68. textButton?.frame = CGRect(x: 10, y: (headerView?.frame ?? .zero).minY+10, width: (bounds.size.width-40)/2, height: 60)
  69. imageButton?.frame = CGRect(x: 30 + (bounds.size.width-40)/2, y: (headerView?.frame ?? .zero).minY+10, width: (bounds.size.width-40)/2, height: 60)
  70. textLabel?.frame = CGRect(x: 10, y: (headerView?.frame ?? .zero).minY+80, width: bounds.size.width-20, height: 20)
  71. }
  72. // MARK: - Button Event Action
  73. @objc func buttonItemClicked_AddImage(_ sender: Any) {
  74. delegate?.addImage?(with: self)
  75. }
  76. @objc func buttonItemClicked_AddText(_ sender: Any) {
  77. delegate?.addText?(with: self)
  78. }
  79. }