PQSectionHeadView.swift 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // PQShareSpaceHeadView.swift
  3. // PQSpeed
  4. //
  5. // Created by SanW on 2020/11/12.
  6. // Copyright © 2020 BytesFlow. All rights reserved.
  7. //
  8. import UIKit
  9. public class PQSectionHeadView: UIView {
  10. // 清除按钮回调
  11. public var btnClickHandle: ((_ sender: UIButton) -> Void)?
  12. // 是否隐藏清除按钮
  13. public var isHiddenClearBtn: Bool = true {
  14. didSet {
  15. clearBtn.isHidden = isHiddenClearBtn
  16. }
  17. }
  18. public var sectionTitle: String? {
  19. didSet {
  20. addData()
  21. addLayout()
  22. }
  23. }
  24. lazy public var lineView: UIView = {
  25. let lineView = UIView()
  26. lineView.backgroundColor = UIColor.hexColor(hexadecimal: "#EE0051")
  27. lineView.addCorner(corner: 1.5)
  28. return lineView
  29. }()
  30. lazy public var titleLab: UILabel = {
  31. let titleLab = UILabel()
  32. titleLab.textColor = UIColor.white
  33. titleLab.font = UIFont(name: "PingFangSC", size: 16)
  34. return titleLab
  35. }()
  36. lazy public var clearBtn: UIButton = {
  37. let clearBtn = UIButton(type: .custom)
  38. clearBtn.setTitle("全部已读 ", for: .normal)
  39. clearBtn.setImage(UIImage.init().BF_Image(named: "msg_clear_noreaded"), for: .normal)
  40. clearBtn.setTitleColor(UIColor.hexColor(hexadecimal: "#666666"), for: .normal)
  41. clearBtn.titleLabel?.font = UIFont(name: "PingFangSC", size: 13)
  42. clearBtn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
  43. clearBtn.isHidden = true
  44. return clearBtn
  45. }()
  46. override public init(frame: CGRect) {
  47. super.init(frame: frame)
  48. addSubviews()
  49. }
  50. override public func layoutSubviews() {
  51. super.layoutSubviews()
  52. // addData()
  53. // addLayout()
  54. }
  55. required public init?(coder _: NSCoder) {
  56. fatalError("init(coder:) has not been implemented")
  57. }
  58. public func addSubviews() {
  59. addSubview(lineView)
  60. addSubview(titleLab)
  61. addSubview(clearBtn)
  62. }
  63. public func addData() {
  64. titleLab.text = sectionTitle
  65. }
  66. public func addLayout() {
  67. let lineW: CGFloat = 3
  68. let lineH: CGFloat = cDefaultMargin * 2
  69. lineView.snp.makeConstraints { make in
  70. make.width.equalTo(lineW)
  71. make.height.equalTo(lineH)
  72. make.centerY.equalToSuperview()
  73. }
  74. titleLab.snp.makeConstraints { make in
  75. make.left.equalTo(lineView.snp_right).offset(lineW * 4)
  76. make.centerY.equalToSuperview()
  77. }
  78. clearBtn.snp.makeConstraints { make in
  79. make.centerY.equalToSuperview()
  80. make.right.equalToSuperview().offset(-cDefaultMargin)
  81. }
  82. clearBtn.imagePosition(at: .right, space: 0)
  83. }
  84. @objc public func btnClick(sender: UIButton) {
  85. if btnClickHandle != nil {
  86. btnClickHandle!(sender)
  87. }
  88. }
  89. }