294 lines
8.5 KiB
Swift
294 lines
8.5 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 { updateCodeBoxes() }
|
|
}
|
|
|
|
@objc func numAction(button: UIButton) {
|
|
textField.becomeFirstResponder()
|
|
}
|
|
|
|
private func updateCodeBoxes() {
|
|
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)
|
|
numberBtns[index].isSelected = true
|
|
}
|
|
|
|
let cursorIndex = characters.count
|
|
if cursorIndex < numberBtns.count {
|
|
numberBtns[cursorIndex].isSelected = true
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
|
|
private func setupUI() {
|
|
addSubview(navBgView)
|
|
addSubview(contentCard)
|
|
addSubview(navView)
|
|
addSubview(textField)
|
|
addSubview(scanBtn)
|
|
|
|
contentCard.addSubview(cardTitleLab)
|
|
contentCard.addSubview(number1)
|
|
contentCard.addSubview(number2)
|
|
contentCard.addSubview(number3)
|
|
contentCard.addSubview(lineView)
|
|
contentCard.addSubview(number4)
|
|
contentCard.addSubview(number5)
|
|
contentCard.addSubview(number6)
|
|
contentCard.addSubview(submitBtn)
|
|
contentCard.addSubview(tipsLab)
|
|
|
|
navBgView.layoutChain
|
|
.top()
|
|
.edgesHorzontal()
|
|
.heightToWidth(224 / 375)
|
|
|
|
navView.layoutChain
|
|
.top()
|
|
.edgesHorzontal()
|
|
.height(kNaviHeight)
|
|
|
|
contentCard.layoutChain
|
|
.topToBottomOfView(navBgView, offset: -31)
|
|
.edgesHorzontal()
|
|
.bottom()
|
|
|
|
cardTitleLab.layoutChain
|
|
.top(17)
|
|
.centerX()
|
|
|
|
lineView.layoutChain
|
|
.topToBottomOfView(cardTitleLab, offset: 62)
|
|
.centerX()
|
|
.width(13)
|
|
.height(5)
|
|
|
|
number3.layoutChain
|
|
.centerY(lineView)
|
|
.rightToLeftOfView(lineView, offset: -10)
|
|
.width(36)
|
|
.height(52)
|
|
|
|
number2.layoutChain
|
|
.topToView(number3)
|
|
.rightToLeftOfView(number3, offset: -10)
|
|
.widthToView(number3)
|
|
.heightToView(number3)
|
|
|
|
number1.layoutChain
|
|
.topToView(number3)
|
|
.rightToLeftOfView(number2, offset: -10)
|
|
.widthToView(number3)
|
|
.heightToView(number3)
|
|
|
|
number4.layoutChain
|
|
.centerY(lineView)
|
|
.leftToRightOfView(lineView, offset: 10)
|
|
.widthToView(number3)
|
|
.heightToView(number3)
|
|
|
|
number5.layoutChain
|
|
.topToView(number3)
|
|
.leftToRightOfView(number4, offset: 10)
|
|
.widthToView(number3)
|
|
.heightToView(number3)
|
|
|
|
number6.layoutChain
|
|
.topToView(number3)
|
|
.leftToRightOfView(number5, offset: 10)
|
|
.widthToView(number3)
|
|
.heightToView(number3)
|
|
|
|
submitBtn.layoutChain
|
|
.topToBottomOfView(number3, offset: 40)
|
|
.edgesHorzontal(24)
|
|
.height(56)
|
|
|
|
tipsLab.layoutChain
|
|
.topToBottomOfView(submitBtn, offset: 16)
|
|
.centerX()
|
|
.edgesHorzontal(24)
|
|
|
|
scanBtn.layoutChain
|
|
.top(kStatusBarHeight + 6)
|
|
.right(18)
|
|
.width(44).height(44)
|
|
}
|
|
|
|
private func styleNavIconButton(_ button: UIButton) {
|
|
button.backgroundColor = .white
|
|
button.cornerRadius = 12
|
|
button.clipsToBounds = true
|
|
}
|
|
|
|
private func makeCodeButton() -> UIButton {
|
|
let button = UIButton(type: .custom)
|
|
button.setTitleColor(.white, for: .selected)
|
|
button.setTitleColor(UIColor(hexStr: "#293445"), for: .normal)
|
|
button.titleLabel?.font = FontManager.youSheBiaoTiHei(30)
|
|
button.setBackgroundColor(UIColor(hexStr: "#16B3FF", alpha: 0.3), for: .normal)
|
|
button.setBackgroundColor(UIColor(hexStr: "#5CBBFF"), for: .selected)
|
|
button.cornerRadius = 12
|
|
button.addTarget(self, action: #selector(numAction), for: .touchUpInside)
|
|
return button
|
|
}
|
|
|
|
lazy var navBgView: UIImageView = {
|
|
let iv = UIImageView()
|
|
iv.image = UIImage(named: "Group/join_hero_bg")
|
|
iv.contentMode = .scaleAspectFill
|
|
iv.clipsToBounds = true
|
|
return iv
|
|
}()
|
|
|
|
lazy var contentCard: UIView = {
|
|
let view = UIView()
|
|
view.backgroundColor = .white
|
|
view.layer.cornerRadius = 30
|
|
view.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
|
|
view.clipsToBounds = true
|
|
return view
|
|
}()
|
|
|
|
lazy var navView: BaseNavigationView = {
|
|
let nav = BaseNavigationView(title: " ")
|
|
return nav
|
|
}()
|
|
|
|
lazy var scanBtn: UIButton = {
|
|
let btn = UIButton(type: .custom)
|
|
btn.setBackgroundImage(UIImage(named: "Group/join_scan"), for: .normal)
|
|
btn.extendEdgeInsets = UIEdgeInsets(top: 10, left: 20, bottom: 20, right: 18)
|
|
return btn
|
|
}()
|
|
|
|
lazy var cardTitleLab: UILabel = {
|
|
let label = UILabel()
|
|
label.text = "请输入邀请码"
|
|
label.font = .systemFont(ofSize: 16, weight: .bold)
|
|
label.textColor = UIColor(hexStr: "#353B4F")
|
|
label.textAlignment = .center
|
|
return label
|
|
}()
|
|
|
|
lazy var tipsLab: UILabel = {
|
|
let label = UILabel()
|
|
label.text = "输入好友分享的邀请码,添加好友专属圈子"
|
|
label.font = .systemFont(ofSize: 14, weight: .medium)
|
|
label.textColor = UIColor(hexStr: "#00ADFE")
|
|
label.textAlignment = .center
|
|
label.numberOfLines = 0
|
|
return label
|
|
}()
|
|
|
|
lazy var number1: UIButton = {
|
|
let button = makeCodeButton()
|
|
button.isSelected = true
|
|
return button
|
|
}()
|
|
|
|
lazy var number2: UIButton = makeCodeButton()
|
|
lazy var number3: UIButton = makeCodeButton()
|
|
lazy var number4: UIButton = makeCodeButton()
|
|
lazy var number5: UIButton = makeCodeButton()
|
|
lazy var number6: UIButton = makeCodeButton()
|
|
|
|
lazy var lineView: UIView = {
|
|
let view = UIView()
|
|
view.backgroundColor = UIColor(hexStr: "#16B3FF")
|
|
view.cornerRadius = 0
|
|
return view
|
|
}()
|
|
|
|
lazy var submitBtn: 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
|
|
return btn
|
|
}()
|
|
|
|
lazy var keyboardConfirmBtn: 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
|
|
return btn
|
|
}()
|
|
|
|
private lazy var keyboardConfirmBar: UIView = {
|
|
let bar = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 68))
|
|
bar.backgroundColor = .white
|
|
|
|
bar.addSubview(keyboardConfirmBtn)
|
|
keyboardConfirmBtn.layoutChain
|
|
.edgesHorzontal(16)
|
|
.top(8)
|
|
.height(52)
|
|
|
|
return bar
|
|
}()
|
|
|
|
lazy var textField: UITextField = {
|
|
let tf = UITextField()
|
|
tf.isHidden = true
|
|
tf.keyboardType = .asciiCapable
|
|
tf.autocorrectionType = .no
|
|
tf.returnKeyType = .done
|
|
// tf.inputAccessoryView = keyboardConfirmBar
|
|
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")
|
|
}
|
|
}
|