/
sberpay
/
AgeGate-iOS
Обзор
Документация
Войти
/
sberpay
/
AgeGate-iOS
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
develop
AgeGateExample/Presentation/ConfigModule/Cells/SwitchCell.swift
67 строк
2 KB
SergeyGladkiy
[0.2.0] БДСЧ сценарий
30 июл 2026, 21:57
30 июл 2026, 21:57
cbcdfcb
Код
Авторство
О чём код?
// // SwitchCell.swift // SPaySdkExample // // Created by Ипатов Александр Станиславович on 25.05.2023. // import UIKit final class SwitchCell: UITableViewCell { private var valueChanged: ((Bool) -> Void)? private lazy var titleLabel: UILabel = { let view = UILabel() view.textColor = .label view.font = .systemFont(ofSize: 15, weight: .regular) view.numberOfLines = 0 return view }() private lazy var switchControl: UISwitch = { let view = UISwitch() view.addTarget(self, action: #selector(switchChanged), for: .valueChanged) return view }() private lazy var stackView: UIStackView = { let view = UIStackView(arrangedSubviews: [titleLabel, switchControl]) view.axis = .horizontal view.alignment = .center view.spacing = 10 view.translatesAutoresizingMaskIntoConstraints = false return view }() override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) selectionStyle = .none setupUI() } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } func config(title: String, value: Bool, valueChanged: @escaping (Bool) -> Void) { titleLabel.text = title switchControl.isOn = value self.valueChanged = valueChanged } @objc private func switchChanged() { valueChanged?(switchControl.isOn) } private func setupUI() { contentView.addSubview(stackView) NSLayoutConstraint.activate([ stackView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 8), stackView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 16), stackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -16), stackView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -8) ]) } }