// // CancelAccountView.swift // QuickLocation // import UIKit final class CancelAccountView: UIView { lazy var navView = BaseNavigationView(title: "注销账号") let scrollView = UIScrollView() let contentView = UIView() let warningIcon = UIImageView(image: UIImage(named: "Mine/cancel_warning")) let introLab = UILabel() let card = UIView() let confirmInput = UITextField() let saveBtn = UIButton(type: .custom) let agreementBtn = UIButton(type: .custom) private(set) var checkItems: [CancelCheckItemView] = [] override init(frame: CGRect) { super.init(frame: frame) backgroundColor = UIColor(hexStr: "#F9F9F9") setupUI() } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } private func setupUI() { addSubview(navView) navView.layoutChain.top().edgesHorzontal().height(kNaviHeight) addSubview(saveBtn) saveBtn.setTitle("保存", for: .normal) saveBtn.titleLabel?.font = FontManager.boboBold(18) saveBtn.setTitleColor(.white, for: .normal) saveBtn.backgroundColor = UIColor(hexStr: "#FF9B9B") saveBtn.layer.cornerRadius = 20 saveBtn.isEnabled = false saveBtn.alpha = 0.5 saveBtn.layoutChain.left(20).right(20).bottom(34).height(56) addSubview(scrollView) scrollView.keyboardDismissMode = .onDrag scrollView.backgroundColor = .clear scrollView.layoutChain .topToBottomOfView(navView) .edgesHorzontal() .bottomToTopOfView(saveBtn, offset: -12) scrollView.addSubview(contentView) contentView.backgroundColor = UIColor(hexStr: "#F9F9F9") contentView.layoutChain.edges().widthToView(scrollView) warningIcon.contentMode = .scaleAspectFit contentView.addSubview(warningIcon) warningIcon.layoutChain.top(24).centerX().width(68).height(68) introLab.text = "为保证你的账号安全,在你提交的注销申请生效前,需要同时满足以下条件:" introLab.font = .systemFont(ofSize: 16, weight: .medium) introLab.textColor = UIColor(hexStr: "#3D3D3D") introLab.numberOfLines = 0 contentView.addSubview(introLab) introLab.layoutChain.topToBottomOfView(warningIcon, offset: 16).edgesHorzontal(20) card.backgroundColor = .white card.layer.cornerRadius = 24 contentView.addSubview(card) card.layoutChain .topToBottomOfView(introLab, offset: 16) .edgesHorzontal(15) .bottom(20) let specs: [(String, String)] = [ ("1. 当前账号没有违规及其他的法律纠纷", "同意请打勾"), ("2. 确认是账号本人进行注销操作,自愿承担后果", "同意请打勾"), ("3. 账号注销后账号不可登录,不可恢复", "同意请打勾") ] var previous: UIView? for spec in specs { let item = CancelCheckItemView(title: spec.0, subtitle: spec.1) checkItems.append(item) card.addSubview(item) if let previous { item.layoutChain.topToBottomOfView(previous).edgesHorzontal(14) } else { item.layoutChain.top(14).edgesHorzontal(14) } previous = item } agreementBtn.setTitle("查看协议", for: .normal) agreementBtn.setTitleColor(UIColor(hexStr: "#08B5FF"), for: .normal) agreementBtn.titleLabel?.font = .systemFont(ofSize: 13, weight: .medium) agreementBtn.contentHorizontalAlignment = .left let agreementItem = CancelCheckItemView( title: "4. 账号注销协议", actionButton: agreementBtn ) checkItems.append(agreementItem) card.addSubview(agreementItem) agreementItem.layoutChain.topToBottomOfView(previous!).edgesHorzontal(14) let tip6 = UILabel() tip6.text = "5. 请在输入框中输入以下文字" tip6.font = .systemFont(ofSize: 16, weight: .medium) tip6.textColor = UIColor(hexStr: "#293445") card.addSubview(tip6) tip6.layoutChain.topToBottomOfView(agreementItem, offset: 12).left(14).right(14) let phrase = UILabel() phrase.text = "我自愿注销本账号" phrase.font = .systemFont(ofSize: 16, weight: .medium) phrase.textColor = UIColor(hexStr: "#F64545") card.addSubview(phrase) phrase.layoutChain.topToBottomOfView(tip6, offset: 8).leftToView(tip6, offset: 16) confirmInput.backgroundColor = UIColor(hexStr: "#F5F5F5") confirmInput.layer.cornerRadius = 8 confirmInput.borderWidth = 1 confirmInput.borderColor = UIColor(hexStr: "#DEDEDE") confirmInput.font = .systemFont(ofSize: 14, weight: .medium) confirmInput.textColor = UIColor(hexStr: "#293445") confirmInput.leftView = UIView(frame: CGRect(x: 0, y: 0, width: 12, height: 1)) confirmInput.leftViewMode = .always confirmInput.rightView = UIView(frame: CGRect(x: 0, y: 0, width: 12, height: 1)) confirmInput.rightViewMode = .always card.addSubview(confirmInput) confirmInput.layoutChain .topToBottomOfView(phrase, offset: 10) .left(14) .right(14) .height(40) .bottom(16) } func setSaveEnabled(_ enabled: Bool) { saveBtn.isEnabled = enabled saveBtn.alpha = enabled ? 1 : 0.5 saveBtn.backgroundColor = UIColor(hexStr: enabled ? "#FF5252" : "#FF9B9B") } } final class CancelCheckItemView: UIView { let checkBtn = UIButton(type: .custom) private let titleLab = UILabel() private let subLab = UILabel() private let actionButton: UIButton? var isChecked: Bool { checkBtn.isSelected } init(title: String, subtitle: String? = nil, actionButton: UIButton? = nil) { self.actionButton = actionButton super.init(frame: .zero) titleLab.text = title titleLab.font = .systemFont(ofSize: 15, weight: .medium) titleLab.textColor = UIColor(hexStr: "#293445") titleLab.numberOfLines = 0 addSubview(titleLab) checkBtn.setBackgroundImage(UIImage(named: "Common/checkbox"), for: .normal) checkBtn.setBackgroundImage(UIImage(named: "Common/checkbox_on"), for: .selected) checkBtn.extendEdgeInsets = UIEdgeInsets(top: 0, left: 20, bottom: 20, right: 20) addSubview(checkBtn) titleLab.layoutChain.top(10).left(0).rightToLeftOfView(checkBtn, offset: 8) checkBtn.layoutChain.right(0).centerY(titleLab).width(24).height(24) if let actionButton { addSubview(actionButton) actionButton.layoutChain .topToBottomOfView(titleLab) .left(0) .width(100) .height(44) .bottom(4) } else { subLab.text = subtitle subLab.font = .systemFont(ofSize: 13, weight: .medium) subLab.textColor = UIColor(hexStr: "#767676") subLab.numberOfLines = 0 addSubview(subLab) subLab.layoutChain .topToBottomOfView(titleLab, offset: 4) .left(0) .rightToLeftOfView(checkBtn, offset: 12) .bottom(10) } } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } }