// // 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) 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. 放弃当前的VIP权益", "当前充值的VIP我们不会退款,请解除你的自动续费(如果有),同意请打勾"), ("2. 当前账号没有违规及其他的法律纠纷", "同意请打勾"), ("3. 确认是账号本人进行注销操作,自愿承担后果", "同意请打勾"), ("4. 账号注销后账号不可登录,不可恢复", "同意请打勾") ] 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 } let tip5 = UILabel() tip5.text = "5. 请在输入框中输入以下文字" tip5.font = .systemFont(ofSize: 16, weight: .medium) tip5.textColor = UIColor(hexStr: "#293445") card.addSubview(tip5) tip5.layoutChain.topToBottomOfView(previous!, 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(tip5, offset: 8).leftToView(tip5, 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() var isChecked: Bool { checkBtn.isSelected } init(title: String, subtitle: String) { super.init(frame: .zero) titleLab.text = title titleLab.font = .systemFont(ofSize: 15, weight: .medium) titleLab.textColor = UIColor(hexStr: "#293445") titleLab.numberOfLines = 0 addSubview(titleLab) subLab.text = subtitle subLab.font = .systemFont(ofSize: 13, weight: .medium) subLab.textColor = UIColor(hexStr: "#767676") subLab.numberOfLines = 0 addSubview(subLab) 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) subLab.layoutChain.topToBottomOfView(titleLab, offset: 4).left(0).rightToLeftOfView(checkBtn, offset: 12).bottom(10) checkBtn.layoutChain.right(0).centerY(titleLab).width(24).height(24) } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } }