/
sberpay
/
AgeGate-iOS
Обзор
Документация
Войти
/
sberpay
/
AgeGate-iOS
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
develop
AgeGateExample/Presentation/CartVC/CustomStepper.swift
76 строк
2 KB
SergeyGladkiy
[0.2.0] БДСЧ сценарий
30 июл 2026, 21:57
30 июл 2026, 21:57
cbcdfcb
Код
Авторство
О чём код?
// // CustomStepper.swift // AgeGateExample // // Created by Гладкий Сергей Игоревич on 24.07.2026. // import UIKit final class CustomStepper: UIView { private var valueChanged: ((Int) -> Void)? private var value = 1 { didSet { countLabel.text = String(value) valueChanged?(value) } } private lazy var minusButton = makeButton(symbol: "minus", action: #selector(decrease)) private lazy var plusButton = makeButton(symbol: "plus", action: #selector(increase)) private lazy var countLabel: UILabel = { let view = UILabel() view.font = .systemFont(ofSize: 15, weight: .medium) view.textAlignment = .center view.widthAnchor.constraint(equalToConstant: 24).isActive = true return view }() private lazy var stackView: UIStackView = { let view = UIStackView(arrangedSubviews: [minusButton, countLabel, plusButton]) view.axis = .horizontal view.alignment = .center view.spacing = 4 view.translatesAutoresizingMaskIntoConstraints = false return view }() init() { super.init(frame: .zero) setupUI() } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } func config(value: Int, valueChanged: @escaping (Int) -> Void) { self.value = value self.valueChanged = valueChanged } @objc private func decrease() { value = max(0, value - 1) } @objc private func increase() { value = min(99, value + 1) } private func makeButton(symbol: String, action: Selector) -> UIButton { let button = UIButton(type: .system) button.setImage(UIImage(systemName: symbol), for: .normal) button.addTarget(self, action: action, for: .touchUpInside) button.widthAnchor.constraint(equalToConstant: 28).isActive = true return button } private func setupUI() { backgroundColor = .secondarySystemBackground layer.cornerRadius = 14 addSubview(stackView) NSLayoutConstraint.activate([ stackView.topAnchor.constraint(equalTo: topAnchor, constant: 4), stackView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 6), stackView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -6), stackView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -4) ]) } }