124 lines
3.4 KiB
Swift
124 lines
3.4 KiB
Swift
//
|
|
// CreateBubbleTiemView.swift
|
|
// QuickLocation
|
|
//
|
|
// Created by 八条 on 2026/6/26.
|
|
//
|
|
|
|
import UIKit
|
|
import RxSwift
|
|
import RxCocoa
|
|
import RxGesture
|
|
|
|
class CreateBubbleTiemView: UIView {
|
|
|
|
var disposeBag = DisposeBag()
|
|
let selectedHour = BehaviorRelay<Int>(value: 1)
|
|
var onNextTap: (() -> Void)?
|
|
private let hours = Array(1...6)
|
|
|
|
private func setupRx() {
|
|
nextBtn.rx.tap.subscribe(onNext: { [weak self] _ in
|
|
self?.onNextTap?()
|
|
}).disposed(by: disposeBag)
|
|
}
|
|
|
|
private func setupUI() {
|
|
addSubview(titleLab)
|
|
addSubview(pickerView)
|
|
addSubview(hourLab)
|
|
addSubview(nextBtn)
|
|
|
|
titleLab.layoutChain
|
|
.top(15)
|
|
.centerX()
|
|
|
|
pickerView.layoutChain
|
|
.centerX().centerY()
|
|
.edgesHorzontal(15)
|
|
.height(180)
|
|
|
|
hourLab.layoutChain
|
|
.centerX(self, offset: 50)
|
|
.centerY(pickerView)
|
|
|
|
nextBtn.layoutChain
|
|
.centerX()
|
|
.width(240)
|
|
.height(50)
|
|
.bottom(kSafeBottomMargin + 10)
|
|
}
|
|
|
|
lazy var titleLab: UILabel = {
|
|
let label = UILabel()
|
|
label.text = "您会在这个气泡里待多久?"
|
|
label.font = .systemFont(ofSize: 20, weight: .bold)
|
|
label.textColor = ThemeManager.shared.color.titleAuxColor
|
|
return label
|
|
}()
|
|
|
|
lazy var pickerView: UIPickerView = {
|
|
let pv = UIPickerView()
|
|
pv.delegate = self
|
|
pv.dataSource = self
|
|
return pv
|
|
}()
|
|
|
|
lazy var hourLab: UILabel = {
|
|
let label = UILabel()
|
|
label.text = "小时"
|
|
label.font = .systemFont(ofSize: 16, weight: .medium)
|
|
label.textColor = UIColor(hexStr: "#16B3FF")
|
|
return label
|
|
}()
|
|
|
|
lazy var nextBtn: UIButton = {
|
|
let btn = UIButton(type: .custom)
|
|
btn.setTitle("下一步", for: .normal)
|
|
btn.setTitleColor(.white, for: .normal)
|
|
btn.titleLabel?.font = .systemFont(ofSize: 16, weight: .medium)
|
|
btn.setBackgroundImage(UIImage(named: "Common/button_bg_2"), for: .normal)
|
|
btn.cornerRadius = 25
|
|
return btn
|
|
}()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: .zero)
|
|
self.isHidden = true
|
|
backgroundColor = .white
|
|
setupUI()
|
|
setupRx()
|
|
}
|
|
|
|
required init?(coder aDecoder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
}
|
|
|
|
extension CreateBubbleTiemView: UIPickerViewDataSource, UIPickerViewDelegate {
|
|
func numberOfComponents(in pickerView: UIPickerView) -> Int {
|
|
1
|
|
}
|
|
|
|
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
|
|
hours.count
|
|
}
|
|
|
|
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
|
|
let label = view as? UILabel ?? UILabel()
|
|
label.textAlignment = .center
|
|
label.font = .systemFont(ofSize: 20, weight: .medium)
|
|
let text = "\(hours[row])"
|
|
let selected = row == pickerView.selectedRow(inComponent: component)
|
|
label.textColor = selected ? UIColor(hexStr: "#16B3FF") : UIColor(hexStr: "#999999")
|
|
label.text = text
|
|
return label
|
|
}
|
|
|
|
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
|
|
selectedHour.accept(hours[row])
|
|
pickerView.reloadAllComponents()
|
|
}
|
|
}
|