-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSelectableItemCell.swift
More file actions
78 lines (65 loc) · 2.52 KB
/
Copy pathSelectableItemCell.swift
File metadata and controls
78 lines (65 loc) · 2.52 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// SelectableItemCell.swift
// Presentation
//
// Created by 최정인 on 7/24/25.
//
import SnapKit
import UIKit
final class SelectableItemCell: UITableViewCell {
private enum Layout {
static let checkIconSize: CGFloat = 16
static let horizontalMargin: CGFloat = 20
}
private let titleLabel = UILabel()
private let checkIcon = UIImageView()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
configureAttribute()
configureLayout()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func configureAttribute() {
titleLabel.font = BitnagilFont(style: .body1, weight: .regular).font
titleLabel.textColor = BitnagilColor.gray10
let checkImage = BitnagilIcon.checkIcon?
.resizeAspectFit(to: CGSize(width: Layout.checkIconSize, height: Layout.checkIconSize))?
.withRenderingMode(.alwaysTemplate)
checkIcon.tintColor = BitnagilColor.orange500
checkIcon.image = checkImage
}
private func configureLayout() {
contentView.addSubview(titleLabel)
contentView.addSubview(checkIcon)
titleLabel.snp.makeConstraints { make in
make.leading.equalToSuperview().offset(Layout.horizontalMargin)
make.centerY.equalToSuperview()
}
checkIcon.snp.makeConstraints { make in
make.trailing.equalToSuperview().inset(Layout.horizontalMargin)
make.centerY.equalToSuperview()
make.size.equalTo(Layout.checkIconSize)
}
}
func configureCell(item: SelectableItem, isSelected: Bool) {
checkIcon.isHidden = !isSelected
guard let displayName = item.displayName else {
titleLabel.text = item.description
return
}
let attributedString = NSMutableAttributedString(string: item.description)
attributedString.addAttribute(
.font,
value: BitnagilFont(style: .body1, weight: .regular).font,
range: NSRange(location: 0, length: item.description.count))
if let range = item.description.range(of: displayName) {
let nsRange = NSRange(range, in: item.description)
attributedString.addAttributes([
.font: BitnagilFont(style: .body1, weight: .semiBold).font
], range: nsRange)
}
titleLabel.attributedText = attributedString
}
}