// // ConfirmPopView.swift // QuickLocation // // Created by 八条 on 2026/6/10. // import UIKit import RxSwift import RxCocoa import URLNavigator class ConfirmPopVC: DLCustomPopVC { var disposeBag = DisposeBag() // MARK: - Accessor public var confirmBlock: (() -> Void)? public var cancelBlock: (() -> Void)? public var titleText: String? { didSet { titleLab.text = titleText } } public var contentText: String? { didSet { contentLab.text = contentText } } public var cancelText: String? { didSet { closeBtn.setTitle(cancelText, for: .normal) } } public var confirmText: String? { didSet { confirmBtn.setTitle(confirmText, for: .normal) } } private func setupSubviews() { contentBgView.addSubview(logoImgView) contentView.addSubview(headerBgImg) if titleText != nil, titleText?.isEmpty == false { contentView.addSubview(titleLab) } if contentText != nil, contentText?.isEmpty == false { contentView.addSubview(contentLab) } if cancelText?.isEmpty == false || confirmText?.isEmpty == false { contentView.addSubview(stackView) } closeBtn.isHidden = !(cancelText?.isEmpty == false) confirmBtn.isHidden = !(confirmText?.isEmpty == false) } private func setupLayout() { logoImgView.layoutChain .left(16) .top(-45) .width(109) .height(109) headerBgImg.layoutChain .edges(excludingEdge: .bottom) .heightToWidth(100/315) var tempView: UIView? if titleText != nil, titleText?.isEmpty == false { titleLab.layoutChain .top(53) .edgesHorzontal(20) tempView = titleLab } if contentText != nil, contentText?.isEmpty == false { if let tempView = tempView { contentLab.layoutChain .edgesHorzontal(20) .topToBottomOfView(tempView, offset: 20) } else { contentLab.layoutChain .top(53) .edgesHorzontal(20) } tempView = contentLab } guard let tempView = tempView else { return } if cancelText?.isEmpty == false || confirmText?.isEmpty == false { stackView.layoutChain .topToBottomOfView(tempView, offset: 30) .left(20) .right(20) .bottom(15) confirmBtn.layoutChain .height(50) closeBtn.layoutChain .height(50) } } // MARK: - UI private lazy var bgView: UIView = { let view = UIView() view.backgroundColor = .black.withAlphaComponent(0.5) return view }() lazy var popView: UIView = { let view = UIView() view.backgroundColor = .clear return view }() lazy var popBgView: UIView = { let view = UIView() view.backgroundColor = .white view.cornerRadius = 30 return view }() lazy var logoImgView: UIImageView = { let view = UIImageView(image: UIImage(named: "Popup/bell")) return view }() lazy var headerBgImg: UIImageView = { let view = UIImageView(image: UIImage(named: "Popup/header_bg")) view.contentMode = .scaleAspectFill return view }() lazy var titleLab: UILabel = { let label = UILabel() label.font = .systemFont(ofSize: 20, weight: .bold) label.textColor = UIColor(hexStr: "#1A1A1A") label.textAlignment = .center label.numberOfLines = 0 return label }() lazy var contentLab: UILabel = { let label = UILabel() label.font = .systemFont(ofSize: 14, weight: .medium) label.textColor = UIColor(hexStr: "#767676") label.textAlignment = .center label.numberOfLines = 0 return label }() lazy var stackView: UIStackView = { let view = UIStackView(arrangedSubviews: [confirmBtn, closeBtn]) view.spacing = 10 view.axis = .vertical view.alignment = .fill view.distribution = .fill return view }() lazy var confirmBtn: UIButton = { let btn = UIButton(type: .custom) btn.setTitle("是", for: .normal) btn.setTitleColor(.white, for: .normal) btn.titleLabel?.font = .systemFont(ofSize: 16, weight: .medium) btn.setBackgroundImage(UIImage(named: "Common/button_bg_2"), for: .normal) btn.cornerRadius = 25 btn.addTouchBlock { [weak self] _ in self?.dismiss(animated: true, completion: { self?.confirmBlock?() }) } return btn }() lazy var closeBtn: UIButton = { let btn = UIButton(type: .custom) btn.setTitle("否", for: .normal) btn.setTitleColor(UIColor(hexStr: "#16B3FF"), for: .normal) btn.titleLabel?.font = .systemFont(ofSize: 16, weight: .medium) btn.backgroundColor = .clear btn.addTouchBlock { [weak self] _ in self?.dismiss(animated: true, completion: { self?.cancelBlock?() }) } return btn }() // MARK: - Lifecycle override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) popStyle = .center centerCornerRadius = 30 } public required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } public override func viewDidLoad() { super.viewDidLoad() setupSubviews() setupLayout() } } public extension UIViewController { /// 显示弹窗 /// - Parameters: /// - title: 标题 /// - message: 文本内容 /// - confirmText: 确认按钮文案 /// - confirmBlock: 确认按钮点击回调 /// - cancelText: 取消按钮文案 /// - cancelBlock: 取消按钮点击回调 func showConfirmPop(showCloseBtn: Bool = true, title: String?=nil, message: String?=nil, confirmText: String?=nil, confirmBlock: (() -> Void)?=nil, cancelText: String?=nil, cancelBlock: (() -> Void)?=nil) { if title == nil && message == nil { return } let vc = ConfirmPopVC() vc.titleText = title vc.contentText = message vc.confirmText = confirmText vc.confirmBlock = confirmBlock vc.cancelText = cancelText vc.cancelBlock = cancelBlock vc.closeBtn.isHidden = !showCloseBtn vc.dimmingClick = showCloseBtn present(vc, animated: true) } static func showConfirmPop(showCloseBtn: Bool = true, title: String?=nil, message: String?=nil, confirmText: String?=nil, confirmBlock: (() -> Void)?=nil, cancelText: String?=nil, cancelBlock: (() -> Void)?=nil) { if title == nil && message == nil { return } let vc = ConfirmPopVC() vc.titleText = title vc.contentText = message vc.confirmText = confirmText vc.confirmBlock = confirmBlock vc.cancelText = cancelText vc.cancelBlock = cancelBlock vc.closeBtn.isHidden = !showCloseBtn vc.dimmingClick = showCloseBtn UIViewController.topMost?.present(vc, animated: true) } }