| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- //
- // QSLTrialExpireAlertView.swift
- // QuickSearchLocation
- //
- // Created by Destiny on 2025/10/23.
- //
- import UIKit
- class QSLTrialExpireAlertView: UIView {
-
- lazy var contentView: UIView = {
-
- let contentViewW = QSLConst.qsl_kScreenW - 60.rpx
- let contentViewH = 152.0.rpx
- let contentView = UIView(frame: CGRect(x: 0, y: 0, width: contentViewW, height: contentViewH))
- contentView.backgroundColor = .clear
- return contentView
- }()
-
-
- lazy var closeButton: UIButton = {
- let btn = UIButton()
- btn.setBackgroundImage(UIImage(named: "vip_pay_failure_close"), for: .normal)
- btn.addTarget(self, action: #selector(closeBtnAction), for: .touchUpInside)
- return btn
- }()
- lazy var popBgImageView : UIImageView = {
- let popBgImageView = UIImageView()
- popBgImageView.contentMode = .scaleAspectFit
- popBgImageView.image = UIImage(named: "vip_pay_failure_back_ground")
- return popBgImageView
- }()
-
- ///中间描述区域
- lazy var middleView : UIView = {
- let middleView = UIView()
- middleView.backgroundColor = .clear
- return middleView
- }()
-
- lazy var oneButton: UIButton = {
-
- let btn = UIButton()
- btn.addRadius(radius: 20.rpx)
- btn.title("去登录")
- btn.textColor(.white)
- btn.mediumFont(14)
- btn.gradientBackgroundColor(color1: .hexStringColor(hexString: "#7F5737"), color2: .hexStringColor(hexString: "#562B0E"), width: 200.rpx, height: 40.rpx, direction: .horizontal)
- btn.addTarget(self, action: #selector(oneBtnAction), for: .touchUpInside)
- return btn
- }()
-
- lazy var firstButton: UIButton = {
-
- let btn = UIButton()
- btn.isHidden = true
- btn.backgroundColor = .hexStringColor(hexString: "#F8F8F8")
- btn.addRadius(radius: 20.rpx)
- btn.title("取消")
- btn.textColor(.hexStringColor(hexString: "#A7A7A7"))
- btn.mediumFont(16)
- btn.addTarget(self, action: #selector(firstBtnAction), for: .touchUpInside)
- return btn
- }()
-
- lazy var secondButton: UIButton = {
-
- let btn = UIButton()
- btn.isHidden = true
- btn.addRadius(radius: 20.rpx)
- btn.title("确认")
- btn.textColor(.white)
- btn.mediumFont(16)
- btn.gradientBackgroundColor(color1: .hexStringColor(hexString: "#15CBA1"), color2: .hexStringColor(hexString: "#1FE0BA"), width: 118.rpx, height: 40.rpx, direction: .horizontal)
- btn.addTarget(self, action: #selector(secondBtnAction), for: .touchUpInside)
- return btn
- }()
-
- var oneBtnClosure: (() -> ())?
-
- var firstBtnClosure: (() -> ())?
-
- var secondBtnClosure: (() -> ())?
-
- var closeBtnClosure: (() -> ())?
-
-
- class func alert(view: UIView,
- isOneBtn: Bool = false,
- oneBtnText: String = "去登录",
- oneBtnClosure: @escaping () -> () = {},
- firstBtnClosure: @escaping () -> () = {},
- secondBtnClosure: @escaping () -> () = {},
- closeBtnClosure: @escaping () -> () = {}) {
-
- let window = QSLRetainPopUpAlertView(frame: CGRect(x: 0, y: 0, width: QSLConst.qsl_kScreenW, height: QSLConst.qsl_kScreenH))
- window.oneButton.title(oneBtnText)
- window.oneButton.isHidden = !isOneBtn
- window.firstButton.isHidden = isOneBtn
- window.secondButton.isHidden = isOneBtn
- window.oneBtnClosure = oneBtnClosure
- window.firstBtnClosure = firstBtnClosure
- window.secondBtnClosure = secondBtnClosure
- window.closeBtnClosure = closeBtnClosure
-
- window.contentView.snp.remakeConstraints { make in
- make.size.equalTo(CGSize(width: QSLConst.qsl_kScreenW - 60.rpx, height: 310.rpx))
- make.center.equalToSuperview()
- }
- view.addSubview(window)
-
- UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) {
- window.backgroundColor = .hexStringColor(hexString: "#000000", alpha: 0.7)
- window.contentView.isHidden = false
- }
- }
-
- override init(frame: CGRect) {
- super.init(frame: frame)
-
- initView()
- }
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
-
- // 单按钮点击事件
- @objc func oneBtnAction() {
- if let oneBtnClosure = self.oneBtnClosure {
- oneBtnClosure()
- }
- removeView()
- }
-
- // 取消按钮点击事件
- @objc func firstBtnAction() {
- if let firstBtnClosure = self.firstBtnClosure {
- firstBtnClosure()
- }
- removeView()
- }
-
- // 确认按钮点击事件
- @objc func secondBtnAction() {
- if let secondBtnClosure = self.secondBtnClosure {
- secondBtnClosure()
- }
- removeView()
- }
-
- // 关闭按钮点击事件
- @objc func closeBtnAction() {
- if let closeBtnClosure = self.closeBtnClosure {
- closeBtnClosure()
- }
- removeView()
- }
-
- // 移除
- @objc func removeView() {
-
- UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) { [weak self] in
- self?.backgroundColor = UIColor.init(white: 0, alpha: 0)
- self?.contentView.isHidden = true
- self?.closeButton.isHidden = true
- } completion: { [weak self] finished in
- self?.removeFromSuperview()
- }
- }
- }
- extension QSLTrialExpireAlertView {
-
- func initView() {
-
- addSubview(contentView)
- contentView.snp.makeConstraints { make in
- make.size.equalTo(CGSize(width: QSLConst.qsl_kScreenW - 60.rpx, height: 152.0.rpx))
- make.center.equalToSuperview()
- }
-
- addSubview(closeButton)
- closeButton.snp.makeConstraints { make in
- make.bottom.equalTo(contentView.snp.top).offset(30.hpx)
- make.right.equalTo(contentView.snp.right).offset(-10.rpx)
- make.size.equalTo(CGSizeMake(24.rpx, 24.rpx))
- }
-
- contentView.addSubview(popBgImageView)
- popBgImageView.snp.makeConstraints { make in
- make.edges.equalToSuperview()
- }
-
- contentView.addSubview(oneButton)
- oneButton.snp.makeConstraints { make in
- //make.top.equalTo(contentLabel.snp.bottom).offset(24.5.rpx)
- make.size.equalTo(CGSize(width: 150.rpx, height: 40.rpx))
- make.centerX.equalToSuperview()
- make.bottom.equalTo(-38.rpx)
- }
-
- contentView.addSubview(firstButton)
- firstButton.snp.makeConstraints { make in
- make.size.equalTo(CGSize(width: 118.rpx, height: 40.rpx))
- make.left.equalTo(24.rpx)
- make.bottom.equalTo(-24.rpx)
- }
-
- contentView.addSubview(secondButton)
- secondButton.snp.makeConstraints { make in
- make.size.equalTo(CGSize(width: 118.rpx, height: 40.rpx))
- make.right.equalTo(-24.rpx)
- make.bottom.equalTo(-24.rpx)
- }
- }
- }
|