// // BubbleKnowledgeView.swift // QuickLocation // import UIKit final class BubbleKnowledgeView: UIView { lazy var navView = BaseNavigationView(title: "气泡知识") private let scrollView = UIScrollView() private let contentView = UIView() override init(frame: CGRect) { super.init(frame: frame) backgroundColor = UIColor(hexStr: "#FAFAFA") setupUI() } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } private func setupUI() { addSubview(navView) navView.layoutChain.top().edgesHorzontal().height(kNaviHeight) addSubview(scrollView) scrollView.layoutChain.topToBottomOfView(navView).edgesHorzontal().bottom() scrollView.addSubview(contentView) contentView.layoutChain.edges().widthToView(scrollView) let sections: [(String, String, Bool)] = [ ("1", "气泡基础知识", true), ("2", "气泡持续时间", false), ("3", "签到", false), ("4", "弹出您的气泡", false) ] var previous: UIView? for item in sections { let block = makeSection(index: item.0, title: item.1, withFeatureList: item.2) contentView.addSubview(block) if let previous { block.layoutChain.topToBottomOfView(previous, offset: 20).edgesHorzontal(16) } else { block.layoutChain.top(16).edgesHorzontal(16) } previous = block } previous?.layoutChain.bottom(24) } private func makeSection(index: String, title: String, withFeatureList: Bool) -> UIView { let card = UIView() card.backgroundColor = .white card.layer.cornerRadius = 16 let badge = UILabel() badge.text = index badge.font = .systemFont(ofSize: 14, weight: .bold) badge.textColor = .white badge.textAlignment = .center badge.backgroundColor = UIColor(hexStr: "#16B3FF") badge.layer.cornerRadius = 8 badge.clipsToBounds = true card.addSubview(badge) badge.layoutChain.top(16).left(16).width(28).height(28) let titleLab = UILabel() titleLab.text = title titleLab.font = .systemFont(ofSize: 16, weight: .bold) titleLab.textColor = UIColor(hexStr: "#293445") card.addSubview(titleLab) titleLab.layoutChain.leftToRightOfView(badge, offset: 10).centerY(badge) let body = UILabel() body.numberOfLines = 0 body.font = .systemFont(ofSize: 14, weight: .medium) body.textColor = UIColor(hexStr: "#767676") card.addSubview(body) body.layoutChain.topToBottomOfView(badge, offset: 12).edgesHorzontal(16) switch index { case "1": body.text = "当您在气泡中时,圈子成员只能看到您创建气泡时的位置,而不是您的实时位置。安全功能仍然有效。" case "2": body.text = "气泡会在设定的时间到期,但您或圈子成员可以提前「弹出」气泡。" case "3": body.text = "虽然气泡有设定到期时间,但完成「签到」也会弹出气泡。" case "4": body.text = "点击「弹出气泡」可手动结束气泡,之后圈子将能看到您的精确位置。" default: break } var bottomAnchor: UIView = body if withFeatureList { let list = makeFeatureList() card.addSubview(list) list.layoutChain.topToBottomOfView(body, offset: 12).edgesHorzontal(16).bottom(16) bottomAnchor = list } else { body.layoutChain.bottom(16) } _ = bottomAnchor return card } private func makeFeatureList() -> UIView { let stack = UIStackView() stack.axis = .vertical stack.spacing = 0 let rows: [(String, String)] = [ ("碰撞提醒", "开启"), ("SOS警报", "开启"), ("位置共享", "开启"), ("低电量通知", "关闭"), ("安全驾驶通知", "关闭"), ("位置通知", "关闭") ] for (i, row) in rows.enumerated() { let line = UIView() let title = UILabel() title.text = row.0 title.font = .systemFont(ofSize: 14, weight: .medium) title.textColor = UIColor(hexStr: "#293445") let status = UILabel() status.text = row.1 status.font = .systemFont(ofSize: 14, weight: .medium) status.textColor = UIColor(hexStr: "#9CA3AF") line.addSubview(title) line.addSubview(status) title.layoutChain.left().centerY().top(12).bottom(12) status.layoutChain.right().centerY() stack.addArrangedSubview(line) if i < rows.count - 1 { let sep = UIView() sep.backgroundColor = UIColor(hexStr: "#F2F2F2") sep.layoutChain.height(0.5) stack.addArrangedSubview(sep) } } return stack } }