// // InviteJoinView.swift // QuickLocation // // Created by 八条 on 2026/6/1. // import UIKit import RxSwift import RxCocoa class InviteJoinView: UIView { var disposeBag = DisposeBag() func configure(model: GroupInfoModel) { groupIcon.image = model.groupIcon groupNameLab.text = model.name groupDescLab.text = model.description groupDescLab.isHidden = model.description.isEmpty tagStack.arrangedSubviews.forEach { tagStack.removeArrangedSubview($0) $0.removeFromSuperview() } let labels = Array(model.labels.prefix(2)) tagStack.isHidden = labels.isEmpty for text in labels { tagStack.addArrangedSubview(Self.makeTagLabel(text)) } } private static func makeTagLabel(_ text: String) -> UILabel { let label = InviteTagLabel() label.text = text label.textColor = UIColor(hexStr: "#D5923F") label.font = .systemFont(ofSize: 10, weight: .medium) label.backgroundColor = UIColor(hexStr: "#FFF9DD") label.cornerRadius = 4 label.clipsToBounds = true label.textAlignment = .center return label } private func setupRx() { inviteCodeView.rx.tapGesture.subscribe { [weak self] _ in guard let code = self?.inviteCodeLab.text, !code.isEmpty else { return } UIPasteboard.general.string = code DLToast.showSuccess(text: "已复制") }.disposed(by: disposeBag) } private func setupUI() { addSubview(navView) addSubview(inviteCardView) inviteCardView.addSubview(cardBgImg) inviteCardView.addSubview(groupView) inviteCardView.addSubview(inviteInfoTitleLab) inviteCardView.addSubview(inviteCodeView) inviteCodeView.addSubview(inviteCodeTipsLab) inviteCodeView.addSubview(inviteCodeLab) inviteCardView.addSubview(inviteTipsLab) inviteCardView.addSubview(scanTipsLab) inviteCardView.addSubview(qrCodeView) qrCodeView.addSubview(qrCodeImgView) addSubview(shareBtn) addSubview(downloadBtn) navView.layoutChain .edges(excludingEdge: .bottom) .height(kNaviHeight) shareBtn.layoutChain .left(30) .bottom(kSafeBottomMargin + 12) .height(56) .width(110) downloadBtn.layoutChain .leftToRightOfView(shareBtn, offset: 16) .right(30) .bottomToView(shareBtn) .heightToView(shareBtn) inviteCardView.layoutChain .topToBottomOfView(navView, offset: 42) .edgesHorzontal(15) .heightToWidth(481/345) cardBgImg.layoutChain.edges() groupView.layoutChain .top(16) .edgesHorzontal(16) inviteInfoTitleLab.layoutChain .topToBottomOfView(groupIcon, offset: 28) .centerX() inviteCodeView.layoutChain .topToBottomOfView(inviteInfoTitleLab, offset: 12) .centerX() .width(200) .height(56) inviteCodeTipsLab.layoutChain .top(8) .centerX() inviteCodeLab.layoutChain .topToBottomOfView(inviteCodeTipsLab, offset: 7) .centerX() inviteTipsLab.layoutChain .topToBottomOfView(inviteCodeView, offset: 10) .centerX() qrCodeView.layoutChain .bottom(42) .centerX() .width(138) .height(138) qrCodeImgView.layoutChain .edges(all: 18) scanTipsLab.layoutChain .bottomToTopOfView(qrCodeView, offset: -8) .centerX() } lazy var navView: BaseNavigationView = { let nav = BaseNavigationView(title: "邀请成员") nav.backBtn.setImage(UIImage(named: "Group/invite_back"), for: .normal) nav.backBtn.layoutChain.width(36).height(36) return nav }() /// 整卡(截图 / 分享用) lazy var inviteCardView: UIView = { let view = UIView() view.backgroundColor = .clear return view }() lazy var cardBgImg: UIImageView = { let view = UIImageView() view.image = UIImage(named: "Group/invite_card_bg") view.contentMode = .scaleAspectFit return view }() lazy var groupView: UIView = { let view = UIView() view.backgroundColor = UIColor(hexStr: "#EEF7FB") view.cornerRadius = 18 view.addSubview(groupIcon) groupIcon.layoutChain .left(12) .edgesVertical(9) .width(52) .heightToWidth(1) view.addSubview(groupNameLab) groupNameLab.layoutChain .topToView(groupIcon, offset: 2) .leftToRightOfView(groupIcon, offset: 10) view.addSubview(tagStack) tagStack.layoutChain .leftToRightOfView(groupNameLab, offset: 6) .centerY(groupNameLab) .right(12, relation: .greaterThanOrEqual) view.addSubview(groupDescLab) groupDescLab.layoutChain .topToBottomOfView(groupNameLab, offset: 14) .leftToView(groupNameLab) .right(24) return view }() lazy var groupIcon: UIImageView = { let view = UIImageView() view.contentMode = .scaleAspectFill view.cornerRadius = 10 view.clipsToBounds = true return view }() lazy var groupNameLab: UILabel = { let label = UILabel() label.font = .systemFont(ofSize: 16, weight: .bold) label.textColor = UIColor(hexStr: "#293445") label.setContentCompressionResistancePriority(.defaultLow, for: .horizontal) return label }() lazy var tagStack: UIStackView = { let view = UIStackView() view.axis = .horizontal view.alignment = .center view.spacing = 4 view.setContentCompressionResistancePriority(.required, for: .horizontal) return view }() lazy var groupDescLab: UILabel = { let label = UILabel() label.font = .systemFont(ofSize: 12, weight: .regular) label.textColor = UIColor(hexStr: "#999999") return label }() lazy var inviteInfoTitleLab: UILabel = { let label = UILabel() label.text = "将此邀请码分享给加入圈子的人" label.font = .systemFont(ofSize: 14, weight: .medium) label.textColor = UIColor(hexStr: "#353B4F") return label }() lazy var inviteTipsLab: UILabel = { let label = UILabel() label.text = "此邀请码有效期为24小时" label.font = .systemFont(ofSize: 12, weight: .regular) label.textColor = UIColor(hexStr: "#00ADFE") return label }() lazy var inviteCodeView: UIView = { let view = UIView() view.borderColor = UIColor(hexStr: "#CCCCCC") view.borderWidth = 1 view.cornerRadius = 10 view.backgroundColor = .white return view }() lazy var inviteCodeTipsLab: UILabel = { let label = UILabel() label.text = "点击复制邀请码" label.font = .systemFont(ofSize: 11, weight: .medium) label.textColor = UIColor(hexStr: "#999999") return label }() lazy var inviteCodeLab: UILabel = { let label = UILabel() label.font = .systemFont(ofSize: 16, weight: .bold) label.textColor = UIColor(hexStr: "#00ADFE") return label }() lazy var scanTipsLab: UILabel = { let label = UILabel() label.text = "扫描以下二维码" label.font = .systemFont(ofSize: 12, weight: .regular) label.textColor = ThemeManager.shared.color.contentColor return label }() lazy var qrCodeView: UIView = { let view = UIView() view.backgroundColor = .white view.borderWidth = 3 view.borderColor = UIColor(hexStr: "#EAEEEF") view.cornerRadius = 34 return view }() lazy var qrCodeImgView: UIImageView = { let view = UIImageView() view.backgroundColor = .white view.contentMode = .scaleAspectFit view.cornerRadius = 8 view.clipsToBounds = true return view }() lazy var shareBtn: UIButton = { let btn = UIButton(type: .custom) btn.setTitle("分享", for: .normal) btn.titleLabel?.font = FontManager.boboBold(18) btn.setTitleColor(UIColor(hexStr: "#00ADFE"), for: .normal) btn.backgroundColor = .white btn.borderWidth = 1 btn.borderColor = UIColor(hexStr: "#00ADFE") btn.cornerRadius = 20 return btn }() lazy var downloadBtn: UIButton = { let btn = UIButton(type: .custom) btn.setTitle("下载图片", for: .normal) btn.setTitleColor(.white, for: .normal) btn.titleLabel?.font = FontManager.boboBold(18) btn.setBackgroundImage(UIImage(named: "Common/button_bg_2"), for: .normal) btn.cornerRadius = 20 btn.clipsToBounds = true return btn }() /// 兼容旧引用:截图目标 var inviteInfoView: UIView { inviteCardView } override init(frame: CGRect) { super.init(frame: .zero) backgroundColor = .clear setupUI() setupRx() } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func layoutSubviews() { super.layoutSubviews() setGradientLayer( frame: bounds, startPoint: CGPoint(x: 0.5, y: 0), endPoint: CGPoint(x: 0.5, y: 1), colors: [UIColor(hexStr: "#A1E8FF"), UIColor(hexStr: "#E4F8FF")], locations: [0, 1] ) } } private class InviteTagLabel: UILabel { private let inset = UIEdgeInsets(top: 2, left: 6, bottom: 2, right: 6) override func drawText(in rect: CGRect) { super.drawText(in: rect.inset(by: inset)) } override var intrinsicContentSize: CGSize { let size = super.intrinsicContentSize return CGSize(width: size.width + inset.left + inset.right, height: size.height + inset.top + inset.bottom) } }