jsdw_ios/QuickLocation/Section/Group/Join/JoinGroupView.swift

320 lines
10 KiB
Swift

//
// JoinGroupView.swift
// QuickLocation
//
// Created by on 2026/6/1.
//
import UIKit
import RxSwift
import RxCocoa
class JoinGroupView: UIView {
var disposeBag = DisposeBag()
var numberBtns: [UIButton] = []
var inviteCode: String = "" {
didSet {
for btn in numberBtns {
btn.setTitle("", for: .normal)
btn.isSelected = false
}
let characters = inviteCode.map { String($0) }
for (index, character) in characters.enumerated() {
numberBtns[index].setTitle(character, for: .normal)
if index < numberBtns.count-1 {
numberBtns[index].isSelected = false
numberBtns[index+1].isSelected = true
}
}
}
}
@objc func numAction(button: UIButton) {
textField.becomeFirstResponder()
}
private func setupRx() {
textField.rx.text
.orEmpty
.subscribe(onNext: { text in
if text.count < 7 {
self.inviteCode = text
}
else {
self.inviteCode = String(text.dropLast(2) + [text.last!])
self.textField.text = self.inviteCode
}
})
.disposed(by: disposeBag)
backBtn.rx.tap.subscribe(onNext: { _ in
AppRouter.shared.popOrDismiss()
}).disposed(by: disposeBag)
scanBtn.rx.tap.subscribe(onNext: { _ in
AppRouter.push(Route.scan)
}).disposed(by: disposeBag)
}
private func setupUI() {
addSubview(navBgView)
addSubview(navBarView)
navBarView.addSubview(navTitleLabel)
navBarView.addSubview(backBtn)
navBarView.addSubview(scanBtn)
addSubview(titleLab)
addSubview(number1)
addSubview(number2)
addSubview(number3)
addSubview(lineView)
addSubview(number4)
addSubview(number5)
addSubview(number6)
addSubview(tipsLab)
addSubview(submitBtn)
addSubview(textField)
navBgView.layoutChain
.edges(excludingEdge: .bottom)
.heightToWidth(160/375)
navBarView.layoutChain
.edges(excludingEdge: .bottom)
.height(kNaviHeight)
navTitleLabel.layoutChain
.top(kStatusBarHeight + 12)
.centerY(backBtn)
.centerX()
scanBtn.layoutChain
.right(15)
.centerY(navTitleLabel)
.width(24).height(24)
backBtn.layoutChain
.centerY(navTitleLabel)
.left(15)
.width(24)
.height(24)
titleLab.layoutChain
.topToBottomOfView(navBarView, offset: 21)
.centerX()
lineView.layoutChain
.topToBottomOfView(titleLab, offset: 58)
.centerX()
.width(10)
.height(4)
number3.layoutChain
.centerY(lineView)
.rightToLeftOfView(lineView, offset: -8)
.width(28)
.height(40)
number2.layoutChain
.topToView(number3)
.rightToLeftOfView(number3, offset: -8)
.widthToView(number3)
.heightToView(number3)
number1.layoutChain
.topToView(number3)
.rightToLeftOfView(number2, offset: -8)
.widthToView(number3)
.heightToView(number3)
number4.layoutChain
.centerY(lineView)
.leftToRightOfView(lineView, offset: 8)
.widthToView(number3)
.heightToView(number3)
number5.layoutChain
.topToView(number3)
.leftToRightOfView(number4, offset: 8)
.widthToView(number3)
.heightToView(number3)
number6.layoutChain
.topToView(number3)
.leftToRightOfView(number5, offset: 8)
.widthToView(number3)
.heightToView(number3)
tipsLab.layoutChain
.topToBottomOfView(lineView, offset: 38)
.centerX()
submitBtn.layoutChain
.bottom(kSafeBottomMargin + 36)
.centerX()
.edgesHorzontal(30)
.height(50)
}
lazy var navBgView: UIImageView = {
let iv = UIImageView()
iv.image = UIImage(named: "Common/navBar_bg_2")
iv.contentMode = .scaleAspectFill
return iv
}()
lazy var navBarView: UIView = {
let view = UIView()
view.backgroundColor = .clear
return view
}()
lazy var navTitleLabel: UILabel = {
let label = UILabel()
label.text = "加入圈子"
label.font = .systemFont(ofSize: 18, weight: .medium)
label.textColor = ThemeManager.shared.color.titleAuxColor
label.textAlignment = .center
return label
}()
lazy var backBtn: UIButton = {
let btn = UIButton(type: .custom)
btn.setImage(UIImage(named: "Common/back"), for: .normal)
btn.extendEdgeInsets = UIEdgeInsets(top: 54, left: 15, bottom: 100, right: 100)
return btn
}()
lazy var scanBtn: UIButton = {
let btn = UIButton(type: .custom)
btn.setImage(UIImage(named: "Group/scan"), for: .normal)
return btn
}()
lazy var titleLab: UILabel = {
let label = UILabel()
label.text = "输入邀请码"
label.font = .systemFont(ofSize: 24, weight: .medium)
label.textColor = ThemeManager.shared.color.titleAuxColor
label.textAlignment = .center
return label
}()
lazy var tipsLab: UILabel = {
let label = UILabel()
label.text = "向圈子创建者询问邀请码"
label.font = .systemFont(ofSize: 12, weight: .medium)
label.textColor = ThemeManager.shared.color.titleAuxColor
return label
}()
lazy var number1: UIButton = {
let button = UIButton (type: .custom)
button.setTitleColor(ThemeManager.shared.color.titleColor, for: .normal)
button.titleLabel?.font = .systemFont(ofSize: 14, weight: .medium)
button.setBackgroundColor(UIColor(hexStr: "#16B3FF").withAlphaComponent(0.3), for: .normal)
button.setBackgroundColor(UIColor(hexStr: "#5CBBFF"), for: .selected)
button.cornerRadius = 4
button.isSelected = true
button.addTarget(self, action: #selector(numAction), for: .touchUpInside)
return button
}()
lazy var number2: UIButton = {
let button = UIButton (type: .custom)
button.setTitleColor(ThemeManager.shared.color.titleColor, for: .normal)
button.titleLabel?.font = .systemFont(ofSize: 14, weight: .medium)
button.setBackgroundColor(UIColor(hexStr: "#16B3FF").withAlphaComponent(0.3), for: .normal)
button.setBackgroundColor(UIColor(hexStr: "#5CBBFF"), for: .selected)
button.addTarget(self, action: #selector(numAction), for: .touchUpInside)
button.cornerRadius = 4
return button
}()
lazy var number3: UIButton = {
let button = UIButton (type: .custom)
button.setTitleColor(ThemeManager.shared.color.titleColor, for: .normal)
button.titleLabel?.font = .systemFont(ofSize: 14, weight: .medium)
button.setBackgroundColor(UIColor(hexStr: "#16B3FF").withAlphaComponent(0.3), for: .normal)
button.setBackgroundColor(UIColor(hexStr: "#5CBBFF"), for: .selected)
button.addTarget(self, action: #selector(numAction), for: .touchUpInside)
button.cornerRadius = 4
return button
}()
lazy var number4: UIButton = {
let button = UIButton (type: .custom)
button.setTitleColor(ThemeManager.shared.color.titleColor, for: .normal)
button.titleLabel?.font = .systemFont(ofSize: 14, weight: .medium)
button.setBackgroundColor(UIColor(hexStr: "#16B3FF").withAlphaComponent(0.3), for: .normal)
button.setBackgroundColor(UIColor(hexStr: "#5CBBFF"), for: .selected)
button.addTarget(self, action: #selector(numAction), for: .touchUpInside)
button.cornerRadius = 4
return button
}()
lazy var number5: UIButton = {
let button = UIButton (type: .custom)
button.setTitleColor(ThemeManager.shared.color.titleColor, for: .normal)
button.titleLabel?.font = .systemFont(ofSize: 14, weight: .medium)
button.setBackgroundColor(UIColor(hexStr: "#16B3FF").withAlphaComponent(0.3), for: .normal)
button.setBackgroundColor(UIColor(hexStr: "#5CBBFF"), for: .selected)
button.addTarget(self, action: #selector(numAction), for: .touchUpInside)
button.cornerRadius = 4
return button
}()
lazy var number6: UIButton = {
let button = UIButton (type: .custom)
button.setTitleColor(ThemeManager.shared.color.titleColor, for: .normal)
button.titleLabel?.font = .systemFont(ofSize: 14, weight: .medium)
button.setBackgroundColor(UIColor(hexStr: "#16B3FF", alpha: 0.3), for: .normal)
button.setBackgroundColor(UIColor(hexStr: "#5CBBFF"), for: .selected)
button.addTarget(self, action: #selector(numAction), for: .touchUpInside)
button.cornerRadius = 4
return button
}()
lazy var lineView: UIView = {
let view = UIView()
view.backgroundColor = UIColor(hexStr: "#16B3FF", alpha: 0.3)
return view
}()
lazy var submitBtn: UIButton = {
let btn = UIButton(type: .custom)
btn.setTitle("加入", for: .normal)
btn.setTitleColor(UIColor(hexStr: "#0F2846"), for: .normal)
btn.titleLabel?.font = .systemFont(ofSize: 16, weight: .medium)
btn.setBackgroundImage(UIImage(named: "Common/gradient_bg"), for: .normal)
btn.cornerRadius = 25
return btn
}()
lazy var textField: UITextField = {
let tf = UITextField()
tf.isHidden = true
tf.keyboardType = .asciiCapable
tf.autocorrectionType = .no
tf.returnKeyType = .done
return tf
}()
override init(frame: CGRect) {
super.init(frame: .zero)
backgroundColor = .white
setupUI()
setupRx()
numberBtns = [number1, number2, number3, number4, number5, number6]
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}