QSLVipResultsAlertView.swift 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. //
  2. // QSLVipResultsAlertView.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by Destiny on 2025/7/29.
  6. //
  7. import UIKit
  8. class QSLVipResultsAlertView: UIView {
  9. lazy var contentView: UIView = {
  10. let contentViewW = QSLConst.qsl_kScreenW - 60.rpx
  11. let contentViewH = 152.0.rpx
  12. let contentView = UIView(frame: CGRect(x: 0, y: 0, width: contentViewW, height: contentViewH))
  13. contentView.backgroundColor = .white
  14. contentView.addRadius(radius: 8.rpx)
  15. contentView.addBorder(borderWidth: 3.rpx, borderColor: .hexStringColor(hexString: "#FFFFFF"))
  16. return contentView
  17. }()
  18. //渐变色
  19. lazy var headerColorView: UIView = {
  20. let headerColorViewW = QSLConst.qsl_kScreenW - 60.rpx
  21. let headerColorView = UIView(frame: CGRect(x: 0, y: 0, width: headerColorViewW, height: 100))
  22. headerColorView.layer.masksToBounds = true
  23. // 创建渐变图层
  24. let gradientLayer = CAGradientLayer()
  25. gradientLayer.frame = headerColorView.bounds
  26. // 设置渐变颜色 (#9EFFEC 到白色)
  27. gradientLayer.colors = [
  28. UIColor(red: 0.62, green: 1.0, blue: 0.93, alpha: 1.0).cgColor, // #9EFFEC
  29. UIColor.white.cgColor
  30. ]
  31. // 设置渐变方向 (180deg 表示从上到下)
  32. gradientLayer.startPoint = CGPoint(x: 0.5, y: 0.0) // 顶部中点
  33. gradientLayer.endPoint = CGPoint(x: 0.5, y: 1.0) // 底部中点
  34. // 添加渐变图层到视图
  35. headerColorView.layer.insertSublayer(gradientLayer, at: 0)
  36. return headerColorView
  37. }()
  38. lazy var titleLabel: UILabel = {
  39. let label = UILabel()
  40. label.text("给我们一个好评呗~")
  41. label.mediumFont(20)
  42. label.textColor = QSLColor.textColor_333
  43. return label
  44. }()
  45. ///中间描述区域
  46. lazy var middleView : UIView = {
  47. let middleView = UIView()
  48. middleView.backgroundColor = .clear
  49. return middleView
  50. }()
  51. lazy var leftMiddleView : UIView = {
  52. let leftMiddleView = UIView(frame: CGRectMake(0, 0, 14.rpx, 1.rpx))
  53. leftMiddleView.gradientBackgroundColor(color1: .hexStringColor(hexString: "#AAAAAA",alpha: 0.0), color2: .hexStringColor(hexString: "#AAAAAA"), width: 14.rpx, height: 1.rpx, direction: .horizontal)
  54. return leftMiddleView
  55. }()
  56. lazy var rithMiddleView : UIView = {
  57. let rithMiddleView = UIView(frame: CGRectMake(0, 0, 14, 1))
  58. rithMiddleView.gradientBackgroundColor(color1: .hexStringColor(hexString: "#AAAAAA"), color2: .hexStringColor(hexString: "#AAAAAA",alpha: 0.0), width: 14.rpx, height: 1.rpx, direction: .horizontal)
  59. return rithMiddleView
  60. }()
  61. lazy var contentLabel: UILabel = {
  62. let label = UILabel()
  63. label.numberOfLines = 0
  64. label.textAlignment = .center
  65. label.text("登录之后才可以发送好友申请")
  66. label.font(12)
  67. label.textColor = .hexStringColor(hexString: "#00000099" ,alpha: 0.4)
  68. label.changeLineSpace(space: 4)
  69. return label
  70. }()
  71. lazy var oneButton: UIButton = {
  72. let btn = UIButton()
  73. btn.addRadius(radius: 20.rpx)
  74. btn.title("去登录")
  75. btn.textColor(.white)
  76. btn.mediumFont(16)
  77. btn.gradientBackgroundColor(color1: .hexStringColor(hexString: "#15CBA1"), color2: .hexStringColor(hexString: "#1FE0BA"), width: 150.rpx, height: 40.rpx, direction: .horizontal)
  78. btn.addTarget(self, action: #selector(oneBtnAction), for: .touchUpInside)
  79. return btn
  80. }()
  81. lazy var firstButton: UIButton = {
  82. let btn = UIButton()
  83. btn.isHidden = true
  84. btn.backgroundColor = .hexStringColor(hexString: "#F8F8F8")
  85. btn.addRadius(radius: 20.rpx)
  86. btn.title("取消")
  87. btn.textColor(.hexStringColor(hexString: "#A7A7A7"))
  88. btn.mediumFont(16)
  89. btn.addTarget(self, action: #selector(firstBtnAction), for: .touchUpInside)
  90. return btn
  91. }()
  92. lazy var secondButton: UIButton = {
  93. let btn = UIButton()
  94. btn.isHidden = true
  95. btn.addRadius(radius: 20.rpx)
  96. btn.title("确认")
  97. btn.textColor(.white)
  98. btn.mediumFont(16)
  99. btn.gradientBackgroundColor(color1: .hexStringColor(hexString: "#15CBA1"), color2: .hexStringColor(hexString: "#1FE0BA"), width: 118.rpx, height: 40.rpx, direction: .horizontal)
  100. btn.addTarget(self, action: #selector(secondBtnAction), for: .touchUpInside)
  101. return btn
  102. }()
  103. lazy var closeButton: UIButton = {
  104. let btn = UIButton()
  105. btn.setBackgroundImage(UIImage(named: "public_btn_close_AAA"), for: .normal)
  106. btn.addTarget(self, action: #selector(closeBtnAction), for: .touchUpInside)
  107. return btn
  108. }()
  109. var oneBtnClosure: (() -> ())?
  110. var firstBtnClosure: (() -> ())?
  111. var secondBtnClosure: (() -> ())?
  112. var closeBtnClosure: (() -> ())?
  113. class func alert(view: UIView,
  114. title: String,
  115. titleAttring: NSAttributedString,
  116. content: String,
  117. isOneBtn: Bool = false,
  118. oneBtnText: String = "去登录",
  119. oneBtnClosure: @escaping () -> () = {},
  120. firstBtnClosure: @escaping () -> () = {},
  121. secondBtnClosure: @escaping () -> () = {},
  122. closeBtnClosure: @escaping () -> () = {}) {
  123. let window = QSLVipResultsAlertView(frame: CGRect(x: 0, y: 0, width: QSLConst.qsl_kScreenW, height: QSLConst.qsl_kScreenH))
  124. if title.count > 0 {
  125. window.titleLabel.text = title
  126. } else {
  127. window.titleLabel.attributedText = titleAttring
  128. }
  129. window.contentLabel.text = content
  130. window.contentLabel.changeLineSpace(space: 4)
  131. window.oneButton.title(oneBtnText)
  132. window.oneButton.isHidden = !isOneBtn
  133. window.firstButton.isHidden = isOneBtn
  134. window.secondButton.isHidden = isOneBtn
  135. window.oneBtnClosure = oneBtnClosure
  136. window.firstBtnClosure = firstBtnClosure
  137. window.secondBtnClosure = secondBtnClosure
  138. window.closeBtnClosure = closeBtnClosure
  139. window.contentView.snp.remakeConstraints { make in
  140. var windowContentH : CGFloat = 189.rpx
  141. make.size.equalTo(CGSize(width: QSLConst.qsl_kScreenW - 60.rpx, height: windowContentH))
  142. make.center.equalToSuperview()
  143. }
  144. view.addSubview(window)
  145. UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) {
  146. window.backgroundColor = .hexStringColor(hexString: "#000000", alpha: 0.7)
  147. window.contentView.isHidden = false
  148. }
  149. }
  150. override init(frame: CGRect) {
  151. super.init(frame: frame)
  152. initView()
  153. }
  154. required init?(coder: NSCoder) {
  155. fatalError("init(coder:) has not been implemented")
  156. }
  157. // 单按钮点击事件
  158. @objc func oneBtnAction() {
  159. if let oneBtnClosure = self.oneBtnClosure {
  160. oneBtnClosure()
  161. }
  162. removeView()
  163. }
  164. // 取消按钮点击事件
  165. @objc func firstBtnAction() {
  166. if let firstBtnClosure = self.firstBtnClosure {
  167. firstBtnClosure()
  168. }
  169. removeView()
  170. }
  171. // 确认按钮点击事件
  172. @objc func secondBtnAction() {
  173. if let secondBtnClosure = self.secondBtnClosure {
  174. secondBtnClosure()
  175. }
  176. removeView()
  177. }
  178. // 关闭按钮点击事件
  179. @objc func closeBtnAction() {
  180. if let closeBtnClosure = self.closeBtnClosure {
  181. closeBtnClosure()
  182. }
  183. removeView()
  184. }
  185. // 移除
  186. @objc func removeView() {
  187. UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) { [weak self] in
  188. self?.backgroundColor = UIColor.init(white: 0, alpha: 0)
  189. self?.contentView.isHidden = true
  190. } completion: { [weak self] finished in
  191. self?.removeFromSuperview()
  192. }
  193. }
  194. }
  195. extension QSLVipResultsAlertView {
  196. func initView() {
  197. addSubview(contentView)
  198. contentView.snp.makeConstraints { make in
  199. make.size.equalTo(CGSize(width: QSLConst.qsl_kScreenW - 60.rpx, height: 152.0.rpx))
  200. make.center.equalToSuperview()
  201. }
  202. contentView.addSubview(headerColorView)
  203. headerColorView.snp.makeConstraints { make in
  204. make.top.equalToSuperview()
  205. make.left.equalToSuperview()
  206. make.right.equalToSuperview()
  207. make.height.equalTo(100)
  208. }
  209. contentView.addSubview(titleLabel)
  210. titleLabel.snp.makeConstraints { make in
  211. make.centerX.equalToSuperview()
  212. make.top.equalTo(40.rpx)
  213. }
  214. //中间区域
  215. contentView.addSubview(middleView)
  216. middleView.snp.makeConstraints { make in
  217. make.top.equalTo(titleLabel.snp.bottom).offset(9.rpx)
  218. make.left.equalTo(0)
  219. make.right.equalTo(0)
  220. make.height.equalTo(21.rpx)
  221. }
  222. middleView.addSubview(contentLabel)
  223. contentLabel.snp.makeConstraints { make in
  224. make.center.equalToSuperview()
  225. make.height.equalTo(21.rpx)
  226. }
  227. middleView.addSubview(leftMiddleView)
  228. leftMiddleView.snp.makeConstraints { make in
  229. make.right.equalTo(contentLabel.snp.left).offset(-6.rpx)
  230. make.centerY.equalToSuperview()
  231. make.size.equalTo(CGSizeMake(14.rpx, 1.rpx))
  232. }
  233. middleView.addSubview(rithMiddleView)
  234. rithMiddleView.snp.makeConstraints { make in
  235. make.left.equalTo(contentLabel.snp.right).offset(6.rpx)
  236. make.centerY.equalToSuperview()
  237. make.size.equalTo(CGSizeMake(14.rpx, 1.rpx))
  238. }
  239. contentView.addSubview(oneButton)
  240. oneButton.snp.makeConstraints { make in
  241. //make.top.equalTo(contentLabel.snp.bottom).offset(24.5.rpx)
  242. make.size.equalTo(CGSize(width: 150.rpx, height: 40.rpx))
  243. make.centerX.equalToSuperview()
  244. make.bottom.equalTo(-24.rpx)
  245. }
  246. contentView.addSubview(firstButton)
  247. firstButton.snp.makeConstraints { make in
  248. make.size.equalTo(CGSize(width: 118.rpx, height: 40.rpx))
  249. make.left.equalTo(24.rpx)
  250. make.bottom.equalTo(-24.rpx)
  251. }
  252. contentView.addSubview(secondButton)
  253. secondButton.snp.makeConstraints { make in
  254. make.size.equalTo(CGSize(width: 118.rpx, height: 40.rpx))
  255. make.right.equalTo(-24.rpx)
  256. make.bottom.equalTo(-24.rpx)
  257. }
  258. contentView.addSubview(closeButton)
  259. closeButton.snp.makeConstraints { make in
  260. make.size.equalTo(CGSize(width: 24.rpx, height: 24.rpx))
  261. make.top.equalTo(12.rpx)
  262. make.right.equalTo(-12.rpx)
  263. }
  264. }
  265. }