QSLFriendRemarkAlertView.swift 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. //
  2. // QSLFriendRemarkAlertView.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by Destiny on 2024/12/5.
  6. //
  7. import UIKit
  8. class QSLFriendRemarkAlertView: UIView {
  9. lazy var contentView: UIView = {
  10. let contentView = UIView(frame: CGRect(x: 0, y: 0, width: QSLConst.qsl_kScreenW - 60.rpx, height: 203.0.rpx))
  11. contentView.backgroundColor = .white
  12. contentView.addRadius(radius: 8.rpx)
  13. return contentView
  14. }()
  15. lazy var titleLabel: UILabel = {
  16. let label = UILabel()
  17. label.text("修改备注")
  18. label.mediumFont(17)
  19. label.textColor = QSLColor.Color_202020
  20. return label
  21. }()
  22. lazy var remarkView: UIView = {
  23. let view = UIView()
  24. view.backgroundColor = QSLColor.backGroundColor
  25. view.addRadius(radius: 4.rpx)
  26. view.addBorder(borderWidth: 1, borderColor: .hexStringColor(hexString: "#F2F2F2"))
  27. return view
  28. }()
  29. lazy var numText: UILabel = {
  30. let label = UILabel()
  31. label.text("0/11")
  32. label.font(13)
  33. label.textColor = .hexStringColor(hexString: "#A7A7A7")
  34. return label
  35. }()
  36. lazy var remarkTextField: UITextField = {
  37. let textField = UITextField()
  38. textField.maxTextNumber = 11
  39. textField.delegate = self
  40. textField.textColor = QSLColor.Color_202020
  41. textField.font = UIFont.textF(15)
  42. textField.placeholder = "请输入备注"
  43. textField.setPlaceholderAttribute(font: UIFont.textF(16), color: UIColor.hexStringColor(hexString: "#A7A7A7"))
  44. return textField
  45. }()
  46. lazy var firstButton: UIButton = {
  47. let btn = UIButton()
  48. btn.backgroundColor = .hexStringColor(hexString: "#F8F8F8")
  49. btn.addRadius(radius: 20.rpx)
  50. btn.title("取消")
  51. btn.textColor(.hexStringColor(hexString: "#A7A7A7"))
  52. btn.mediumFont(16)
  53. btn.addTarget(self, action: #selector(firstBtnAction), for: .touchUpInside)
  54. return btn
  55. }()
  56. lazy var secondButton: UIButton = {
  57. let btn = UIButton()
  58. btn.addRadius(radius: 20.rpx)
  59. btn.title("确认")
  60. btn.textColor(.white)
  61. btn.mediumFont(16)
  62. btn.gradientBackgroundColor(color1: .hexStringColor(hexString: "#15CBA1"), color2: .hexStringColor(hexString: "#1FE0BA"), width: 118.rpx, height: 40.rpx, direction: .horizontal)
  63. btn.addTarget(self, action: #selector(secondBtnAction), for: .touchUpInside)
  64. return btn
  65. }()
  66. lazy var closeButton: UIButton = {
  67. let btn = UIButton()
  68. btn.setBackgroundImage(UIImage(named: "public_btn_close_AAA"), for: .normal)
  69. btn.addTarget(self, action: #selector(removeView), for: .touchUpInside)
  70. return btn
  71. }()
  72. var secondBtnClosure: ((String) -> ())?
  73. class func alert(view: UIView,
  74. secondBtnClosure: @escaping (String) -> ()) {
  75. let window = QSLFriendRemarkAlertView(frame: CGRect(x: 0, y: 0, width: QSLConst.qsl_kScreenW, height: QSLConst.qsl_kScreenH))
  76. window.secondBtnClosure = secondBtnClosure
  77. view.addSubview(window)
  78. gravityInstance?.track(QSLGravityConst.friend_remark_show)
  79. UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) {
  80. window.backgroundColor = .hexStringColor(hexString: "#000000", alpha: 0.7)
  81. window.contentView.isHidden = false
  82. }
  83. }
  84. override init(frame: CGRect) {
  85. super.init(frame: frame)
  86. initUI()
  87. }
  88. required init?(coder: NSCoder) {
  89. fatalError("init(coder:) has not been implemented")
  90. }
  91. // 取消按钮点击事件
  92. @objc func firstBtnAction() {
  93. gravityInstance?.track(QSLGravityConst.friend_remark_cancel)
  94. removeView()
  95. }
  96. // 确认按钮点击事件
  97. @objc func secondBtnAction() {
  98. gravityInstance?.track(QSLGravityConst.friend_remark_click)
  99. guard let text = self.remarkTextField.text, text.count > 0 else {
  100. UIApplication.keyWindow?.toast(text: "请输入名称")
  101. return
  102. }
  103. if let secondBtnClosure = self.secondBtnClosure {
  104. secondBtnClosure(text)
  105. }
  106. removeView()
  107. }
  108. // 移除
  109. @objc func removeView() {
  110. UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) { [weak self] in
  111. self?.backgroundColor = UIColor.init(white: 0, alpha: 0)
  112. self?.contentView.isHidden = true
  113. } completion: { [weak self] finished in
  114. self?.removeFromSuperview()
  115. }
  116. }
  117. }
  118. extension QSLFriendRemarkAlertView: UITextFieldDelegate {
  119. func textFieldDidChangeSelection(_ textField: UITextField) {
  120. let numCount = textField.text?.count
  121. self.numText.text = "\(numCount ?? 0)/11"
  122. }
  123. }
  124. extension QSLFriendRemarkAlertView {
  125. func initUI() {
  126. addSubview(contentView)
  127. contentView.snp.makeConstraints { make in
  128. make.size.equalTo(CGSize(width: QSLConst.qsl_kScreenW - 60.rpx, height: 203.0.rpx))
  129. make.center.equalToSuperview()
  130. }
  131. contentView.addSubview(titleLabel)
  132. titleLabel.snp.makeConstraints { make in
  133. make.centerX.equalToSuperview()
  134. make.top.equalTo(24.rpx)
  135. }
  136. contentView.addSubview(remarkView)
  137. remarkView.snp.makeConstraints { make in
  138. make.left.equalTo(29.rpx)
  139. make.right.equalTo(-19.rpx)
  140. make.top.equalTo(65.rpx)
  141. make.height.equalTo(46.rpx)
  142. }
  143. remarkView.addSubview(numText)
  144. numText.snp.makeConstraints { make in
  145. make.right.equalTo(-12.rpx)
  146. make.width.equalTo(32.rpx)
  147. make.centerY.equalToSuperview()
  148. }
  149. remarkView.addSubview(remarkTextField)
  150. remarkTextField.snp.makeConstraints { make in
  151. make.left.equalTo(12.rpx)
  152. make.top.bottom.equalTo(0)
  153. make.right.equalTo(numText.snp.left).offset(-12.rpx)
  154. }
  155. contentView.addSubview(firstButton)
  156. firstButton.snp.makeConstraints { make in
  157. make.size.equalTo(CGSize(width: 118.rpx, height: 40.rpx))
  158. make.left.equalTo(24.rpx)
  159. make.bottom.equalTo(-24.rpx)
  160. }
  161. contentView.addSubview(secondButton)
  162. secondButton.snp.makeConstraints { make in
  163. make.size.equalTo(CGSize(width: 118.rpx, height: 40.rpx))
  164. make.right.equalTo(-24.rpx)
  165. make.bottom.equalTo(-24.rpx)
  166. }
  167. contentView.addSubview(closeButton)
  168. closeButton.snp.makeConstraints { make in
  169. make.size.equalTo(CGSize(width: 24.rpx, height: 24.rpx))
  170. make.top.equalTo(12.rpx)
  171. make.right.equalTo(-12.rpx)
  172. }
  173. }
  174. }