-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBitnagilToggleTableViewCell.swift
More file actions
60 lines (48 loc) · 1.79 KB
/
BitnagilToggleTableViewCell.swift
File metadata and controls
60 lines (48 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// BitnagilToggleTableViewCell.swift
// Presentation
//
// Created by 이동현 on 7/30/25.
//
import SnapKit
import UIKit
protocol BitnagilToggleTableViewCellDelegate: AnyObject {
func bitnagilToggleTableViewCellDidToggle(_ sender: BitnagilToggleTableViewCell, isOn: Bool)
}
final class BitnagilToggleTableViewCell: BitnagilBaseTableViewCell {
private enum Layout {
static let switchTrailingSpacing: CGFloat = 20
static let switchHeight: CGFloat = 24
static let switchWidth: CGFloat = 44
}
private let toggleSwitch = UISwitch()
weak var delegate: BitnagilToggleTableViewCellDelegate?
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func configureAttribute() {
super.configureAttribute()
toggleSwitch.onTintColor = BitnagilColor.navy500
toggleSwitch.tintColor = BitnagilColor.gray95
toggleSwitch.addAction(UIAction { [weak self] action in
guard let self = self else { return }
self.delegate?.bitnagilToggleTableViewCellDidToggle(self, isOn: toggleSwitch.isOn)
}, for: .valueChanged)
}
override func configureLayout() {
super.configureLayout()
contentView.addSubview(toggleSwitch)
toggleSwitch.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.trailing.equalToSuperview().inset(Layout.switchTrailingSpacing)
make.height.equalTo(Layout.switchHeight)
make.width.equalTo(Layout.switchWidth)
}
}
func configureToggleState(isOn: Bool) {
toggleSwitch.isOn = isOn
}
}