QSLVipResultsNoMemberAlertView.swift 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. //
  2. // QSLVipResultsNoMemberAlertView.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by Destiny on 2025/7/29.
  6. //
  7. import UIKit
  8. class QSLVipResultsNoMemberAlertView: 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 adView : UIView = {
  47. let adView = UIView(frame: CGRectMake(0, 0, 188, 96.2))
  48. // 设置阴影
  49. layer.masksToBounds = false
  50. layer.shadowColor = UIColor(red: 7/255.0, green: 78/255.0, blue: 82/255.0, alpha: 0.16).cgColor
  51. layer.shadowOpacity = 1
  52. layer.shadowOffset = CGSize(width: 1, height: 6)
  53. layer.shadowRadius = 8.rpx
  54. layer.shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: layer.cornerRadius).cgPath
  55. layer.shouldRasterize = true
  56. layer.rasterizationScale = UIScreen.main.scale
  57. adView.addRadius(radius: 8.rpx)
  58. adView.addBorder(borderWidth: 1.rpx, borderColor: .hexStringColor(hexString: "#034249"))
  59. return adView
  60. }()
  61. lazy var adBgImage : UIImageView = {
  62. let adBgImage = UIImageView()
  63. adBgImage.contentMode = .scaleAspectFill
  64. adBgImage.image = UIImage(named: "vip_comment_content_bg")
  65. return adBgImage
  66. } ()
  67. lazy var sunlightImage : UIImageView = {
  68. let sunlightImage = UIImageView()
  69. sunlightImage.contentMode = .scaleAspectFill
  70. sunlightImage.image = UIImage(named: "vip_comment_sunlight")
  71. return sunlightImage
  72. } ()
  73. lazy var adContentLabel: UILabel = {
  74. let label = UILabel()
  75. label.numberOfLines = 0
  76. label.textAlignment = .left
  77. label.text("登录之后才可以发送好友申请")
  78. label.font(12)
  79. label.textColor = .hexStringColor(hexString: "#00000099" ,alpha: 0.4)
  80. label.changeLineSpace(space: 4)
  81. return label
  82. }()
  83. ///中间描述区域
  84. lazy var middleView : UIView = {
  85. let middleView = UIView()
  86. middleView.backgroundColor = .clear
  87. return middleView
  88. }()
  89. lazy var contentLabel: UILabel = {
  90. let label = UILabel()
  91. label.numberOfLines = 0
  92. label.textAlignment = .center
  93. label.text("登录之后才可以发送好友申请")
  94. label.font(12)
  95. label.textColor = .hexStringColor(hexString: "#00000099" ,alpha: 0.4)
  96. label.changeLineSpace(space: 4)
  97. return label
  98. }()
  99. lazy var leftMiddleView : UIView = {
  100. let leftMiddleView = UIView(frame: CGRectMake(0, 0, 14.rpx, 1.rpx))
  101. leftMiddleView.gradientBackgroundColor(color1: .hexStringColor(hexString: "#AAAAAA",alpha: 0.0), color2: .hexStringColor(hexString: "#AAAAAA"), width: 14.rpx, height: 1.rpx, direction: .horizontal)
  102. return leftMiddleView
  103. }()
  104. lazy var rithMiddleView : UIView = {
  105. let rithMiddleView = UIView(frame: CGRectMake(0, 0, 14, 1))
  106. rithMiddleView.gradientBackgroundColor(color1: .hexStringColor(hexString: "#AAAAAA"), color2: .hexStringColor(hexString: "#AAAAAA",alpha: 0.0), width: 14.rpx, height: 1.rpx, direction: .horizontal)
  107. return rithMiddleView
  108. }()
  109. //中间广告提示
  110. lazy var advertsingPromptView : UIView = {
  111. let advertsingPromptView = UIView()
  112. return advertsingPromptView
  113. }()
  114. lazy var oneButton: UIButton = {
  115. let btn = UIButton()
  116. btn.addRadius(radius: 20.rpx)
  117. btn.title("去登录")
  118. btn.textColor(.white)
  119. btn.mediumFont(16)
  120. btn.gradientBackgroundColor(color1: .hexStringColor(hexString: "#15CBA1"), color2: .hexStringColor(hexString: "#1FE0BA"), width: 150.rpx, height: 40.rpx, direction: .horizontal)
  121. btn.addTarget(self, action: #selector(oneBtnAction), for: .touchUpInside)
  122. return btn
  123. }()
  124. lazy var firstButton: UIButton = {
  125. let btn = UIButton()
  126. btn.isHidden = true
  127. btn.backgroundColor = .hexStringColor(hexString: "#F8F8F8")
  128. btn.addRadius(radius: 20.rpx)
  129. btn.title("取消")
  130. btn.textColor(.hexStringColor(hexString: "#A7A7A7"))
  131. btn.mediumFont(16)
  132. btn.addTarget(self, action: #selector(firstBtnAction), for: .touchUpInside)
  133. return btn
  134. }()
  135. lazy var secondButton: UIButton = {
  136. let btn = UIButton()
  137. btn.isHidden = true
  138. btn.addRadius(radius: 20.rpx)
  139. btn.title("确认")
  140. btn.textColor(.white)
  141. btn.mediumFont(16)
  142. btn.gradientBackgroundColor(color1: .hexStringColor(hexString: "#15CBA1"), color2: .hexStringColor(hexString: "#1FE0BA"), width: 118.rpx, height: 40.rpx, direction: .horizontal)
  143. btn.addTarget(self, action: #selector(secondBtnAction), for: .touchUpInside)
  144. return btn
  145. }()
  146. lazy var closeButton: UIButton = {
  147. let btn = UIButton()
  148. btn.setBackgroundImage(UIImage(named: "public_btn_close_AAA"), for: .normal)
  149. btn.addTarget(self, action: #selector(closeBtnAction), for: .touchUpInside)
  150. return btn
  151. }()
  152. var oneBtnClosure: (() -> ())?
  153. var firstBtnClosure: (() -> ())?
  154. var secondBtnClosure: (() -> ())?
  155. var closeBtnClosure: (() -> ())?
  156. class func alert(view: UIView,
  157. title: String,
  158. titleAttring: NSAttributedString,
  159. content: String,
  160. bottomContentAttring: NSAttributedString,
  161. isOneBtn: Bool = false,
  162. oneBtnText: String = "去登录",
  163. oneBtnClosure: @escaping () -> () = {},
  164. firstBtnClosure: @escaping () -> () = {},
  165. secondBtnClosure: @escaping () -> () = {},
  166. closeBtnClosure: @escaping () -> () = {}) {
  167. let window = QSLVipResultsNoMemberAlertView(frame: CGRect(x: 0, y: 0, width: QSLConst.qsl_kScreenW, height: QSLConst.qsl_kScreenH))
  168. if title.count > 0 {
  169. window.titleLabel.text = title
  170. } else {
  171. window.titleLabel.attributedText = titleAttring
  172. }
  173. window.contentLabel.text = content
  174. window.contentLabel.changeLineSpace(space: 4)
  175. window.adContentLabel.attributedText = bottomContentAttring
  176. window.oneButton.title(oneBtnText)
  177. window.oneButton.isHidden = !isOneBtn
  178. window.firstButton.isHidden = isOneBtn
  179. window.secondButton.isHidden = isOneBtn
  180. window.oneBtnClosure = oneBtnClosure
  181. window.firstBtnClosure = firstBtnClosure
  182. window.secondBtnClosure = secondBtnClosure
  183. window.closeBtnClosure = closeBtnClosure
  184. window.contentView.snp.remakeConstraints { make in
  185. make.size.equalTo(CGSize(width: QSLConst.qsl_kScreenW - 60.rpx, height: 290.rpx))
  186. make.center.equalToSuperview()
  187. }
  188. view.addSubview(window)
  189. UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) {
  190. window.backgroundColor = .hexStringColor(hexString: "#000000", alpha: 0.7)
  191. window.contentView.isHidden = false
  192. }
  193. }
  194. override init(frame: CGRect) {
  195. super.init(frame: frame)
  196. initView()
  197. }
  198. required init?(coder: NSCoder) {
  199. fatalError("init(coder:) has not been implemented")
  200. }
  201. // 单按钮点击事件
  202. @objc func oneBtnAction() {
  203. if let oneBtnClosure = self.oneBtnClosure {
  204. oneBtnClosure()
  205. }
  206. removeView()
  207. }
  208. // 取消按钮点击事件
  209. @objc func firstBtnAction() {
  210. if let firstBtnClosure = self.firstBtnClosure {
  211. firstBtnClosure()
  212. }
  213. removeView()
  214. }
  215. // 确认按钮点击事件
  216. @objc func secondBtnAction() {
  217. if let secondBtnClosure = self.secondBtnClosure {
  218. secondBtnClosure()
  219. }
  220. removeView()
  221. }
  222. // 关闭按钮点击事件
  223. @objc func closeBtnAction() {
  224. if let closeBtnClosure = self.closeBtnClosure {
  225. closeBtnClosure()
  226. }
  227. removeView()
  228. }
  229. // 移除
  230. @objc func removeView() {
  231. UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) { [weak self] in
  232. self?.backgroundColor = UIColor.init(white: 0, alpha: 0)
  233. self?.contentView.isHidden = true
  234. } completion: { [weak self] finished in
  235. self?.removeFromSuperview()
  236. }
  237. }
  238. }
  239. extension QSLVipResultsNoMemberAlertView {
  240. func initView() {
  241. addSubview(contentView)
  242. contentView.snp.makeConstraints { make in
  243. make.size.equalTo(CGSize(width: QSLConst.qsl_kScreenW - 60.rpx, height: 152.0.rpx))
  244. make.center.equalToSuperview()
  245. }
  246. contentView.addSubview(headerColorView)
  247. headerColorView.snp.makeConstraints { make in
  248. make.top.equalToSuperview()
  249. make.left.equalToSuperview()
  250. make.right.equalToSuperview()
  251. make.height.equalTo(100)
  252. }
  253. contentView.addSubview(sunlightImage)
  254. sunlightImage.snp.makeConstraints { make in
  255. make.centerX.equalToSuperview()
  256. make.top.equalToSuperview().offset(72.rpx)
  257. make.size.equalTo(CGSizeMake(177.rpx, 177.rpx))
  258. }
  259. contentView.addSubview(titleLabel)
  260. titleLabel.snp.makeConstraints { make in
  261. make.centerX.equalToSuperview()
  262. make.top.equalTo(26.rpx)
  263. }
  264. //中间区域
  265. contentView.addSubview(middleView)
  266. middleView.snp.makeConstraints { make in
  267. make.top.equalTo(titleLabel.snp.bottom).offset(9.rpx)
  268. make.left.equalTo(0)
  269. make.right.equalTo(0)
  270. make.height.equalTo(21.rpx)
  271. }
  272. middleView.addSubview(contentLabel)
  273. contentLabel.snp.makeConstraints { make in
  274. make.center.equalToSuperview()
  275. make.height.equalTo(21.rpx)
  276. }
  277. middleView.addSubview(leftMiddleView)
  278. leftMiddleView.snp.makeConstraints { make in
  279. make.right.equalTo(contentLabel.snp.left).offset(-6.rpx)
  280. make.centerY.equalToSuperview()
  281. make.size.equalTo(CGSizeMake(14.rpx, 1.rpx))
  282. }
  283. middleView.addSubview(rithMiddleView)
  284. rithMiddleView.snp.makeConstraints { make in
  285. make.left.equalTo(contentLabel.snp.right).offset(6.rpx)
  286. make.centerY.equalToSuperview()
  287. make.size.equalTo(CGSizeMake(14.rpx, 1.rpx))
  288. }
  289. ///广告区域
  290. contentView.addSubview(adView)
  291. adView.snp.makeConstraints { make in
  292. make.centerX.equalToSuperview()
  293. make.top.equalTo(middleView.snp.bottom).offset(24.5.rpx)
  294. make.left.equalToSuperview().offset(44.rpx)
  295. make.right.equalToSuperview().offset(-44.rpx)
  296. make.height.equalTo(96.2.rpx)
  297. //make.size.equalTo(CGSizeMake(188.rpx, 96.2.rpx))
  298. }
  299. adView.addSubview(adBgImage)
  300. adBgImage.snp.makeConstraints { make in
  301. make.edges.equalToSuperview()
  302. }
  303. // adView.addSubview(adTitleLabel)
  304. // adTitleLabel.snp.makeConstraints { make in
  305. // make.top.equalToSuperview().offset(10.rpx)
  306. // make.left.equalToSuperview().offset(12.rpx)
  307. // make.right.equalToSuperview()
  308. // make.height.equalTo(13.5.rpx)
  309. // }
  310. // adView.addSubview(adAccessImage)
  311. // adAccessImage.snp.makeConstraints { make in
  312. // make.right.equalToSuperview()
  313. // make.bottom.equalToSuperview()
  314. // make.size.equalTo(CGSizeMake(86.5.rpx, 43.8.rpx))
  315. // }
  316. adView.addSubview(adContentLabel)
  317. adContentLabel.snp.makeConstraints { make in
  318. make.left.equalToSuperview().offset(10.28.rpx)
  319. make.bottom.equalToSuperview().offset(-8.37)
  320. //make.right.equalToSuperview()
  321. }
  322. contentView.addSubview(oneButton)
  323. oneButton.snp.makeConstraints { make in
  324. //make.top.equalTo(contentLabel.snp.bottom).offset(24.5.rpx)
  325. make.size.equalTo(CGSize(width: 150.rpx, height: 40.rpx))
  326. make.centerX.equalToSuperview()
  327. make.bottom.equalTo(-24.rpx)
  328. }
  329. contentView.addSubview(firstButton)
  330. firstButton.snp.makeConstraints { make in
  331. make.size.equalTo(CGSize(width: 118.rpx, height: 40.rpx))
  332. make.left.equalTo(24.rpx)
  333. make.bottom.equalTo(-24.rpx)
  334. }
  335. contentView.addSubview(secondButton)
  336. secondButton.snp.makeConstraints { make in
  337. make.size.equalTo(CGSize(width: 118.rpx, height: 40.rpx))
  338. make.right.equalTo(-24.rpx)
  339. make.bottom.equalTo(-24.rpx)
  340. }
  341. contentView.addSubview(closeButton)
  342. closeButton.snp.makeConstraints { make in
  343. make.size.equalTo(CGSize(width: 24.rpx, height: 24.rpx))
  344. make.top.equalTo(12.rpx)
  345. make.right.equalTo(-12.rpx)
  346. }
  347. }
  348. }