Files
suixinkan_uikit/suixinkan/UI/Orders/Views/OrderGiftStepperView.swift

62 lines
2.0 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// OrderGiftStepperView.swift
// suixinkan
//
import SnapKit
import UIKit
/// /+/- Android
final class OrderGiftStepperView: UIView {
var onMinusTap: (() -> Void)?
var onPlusTap: (() -> Void)?
private let minusButton = UIButton(type: .system)
private let plusButton = UIButton(type: .system)
private let valueLabel = UILabel()
override init(frame: CGRect) {
super.init(frame: frame)
[minusButton, plusButton].forEach { button in
button.layer.cornerRadius = 12
button.layer.borderWidth = 1
button.layer.borderColor = OrderTokens.giftBorder.cgColor
button.titleLabel?.font = .systemFont(ofSize: 16, weight: .bold)
button.setTitleColor(OrderTokens.giftBorder, for: .normal)
button.snp.makeConstraints { make in
make.width.height.equalTo(24)
}
}
minusButton.setTitle("-", for: .normal)
plusButton.setTitle("+", for: .normal)
minusButton.addTarget(self, action: #selector(minusTapped), for: .touchUpInside)
plusButton.addTarget(self, action: #selector(plusTapped), for: .touchUpInside)
valueLabel.font = .systemFont(ofSize: 14, weight: .medium)
valueLabel.textColor = OrderTokens.valueBlack
valueLabel.textAlignment = .center
let stack = UIStackView(arrangedSubviews: [minusButton, valueLabel, plusButton])
stack.axis = .horizontal
stack.spacing = AppSpacing.xs
stack.alignment = .center
addSubview(stack)
stack.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func apply(text: String) {
valueLabel.text = text
}
@objc private func minusTapped() { onMinusTap?() }
@objc private func plusTapped() { onPlusTap?() }
}