MyRewardsProfileInfoTableViewCell.swift
4.76 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//
// MyRewardsProfileInfoTableViewCell.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 23/7/25.
//
import UIKit
protocol MyRewardsProfileInfoTableViewCellDelegate: AnyObject {
func didTapProfileButton()
}
@objc(MyRewardsProfileInfoTableViewCell)
public class MyRewardsProfileInfoTableViewCell: UITableViewCell {
// MARK: - IBOutlets
/// Bold "Rewards" title label (top-left)
@IBOutlet weak var titleLabel: UILabel!
/// Horizontally scrollable container for tag pills
@IBOutlet weak var tagsScrollView: UIScrollView!
/// Horizontal stack view inside the scroll view; tag pill views are added here dynamically
@IBOutlet weak var tagsStackView: UIStackView!
/// Settings / gear button (top-right)
@IBOutlet weak var profileButton: UIButton!
// MARK: - Delegate
weak var delegate: MyRewardsProfileInfoTableViewCellDelegate?
// MARK: - Private
private var profileModel: ProfileModel?
// MARK: - Lifecycle
public override func awakeFromNib() {
super.awakeFromNib()
selectionStyle = .none
// Title
titleLabel.font = UIFont(name: "PingLCG-Bold", size: 26)
?? UIFont.boldSystemFont(ofSize: 26)
titleLabel.textColor = UIColor(rgb: 0x1D2023)
titleLabel.text = "Rewards"
// Gear button: render image as-is (no tint) so the gray circle style is preserved
let gearImage = UIImage(named: "settings_circle", in: Bundle.frameworkResourceBundle, compatibleWith: nil)?
.withRenderingMode(.alwaysOriginal)
profileButton.setImage(gearImage, for: .normal)
profileButton.setTitle("", for: .normal)
profileButton.addTarget(self, action: #selector(profileButtonTapped), for: .touchUpInside)
// Tags scroll view
tagsScrollView.showsHorizontalScrollIndicator = false
tagsScrollView.showsVerticalScrollIndicator = false
// Tags stack view
tagsStackView.axis = .horizontal
tagsStackView.spacing = 9
tagsStackView.alignment = .center
tagsStackView.distribution = .fill
}
public override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
public override func prepareForReuse() {
super.prepareForReuse()
clearTags()
}
// MARK: - Actions
@objc private func profileButtonTapped() {
delegate?.didTapProfileButton()
}
// MARK: - Configuration
public func configureCell(data: SectionModel?) {
guard let data = data,
data.sectionType == .myRewardsProfileInfo else {
configureDefaultState()
return
}
if let metadata = data.metadata,
let profile = metadata["profile"] as? ProfileModel {
configureCell(profile: profile)
} else {
configureDefaultState()
}
}
public func configureCell(profile: ProfileModel) {
self.profileModel = profile
populateTags(segments: profile._user_segments)
}
private func configureDefaultState() {
self.profileModel = nil
clearTags()
}
// MARK: - Tag Helpers
/// Removes all tag pill views from the stack view.
private func clearTags() {
tagsStackView.arrangedSubviews.forEach { $0.removeFromSuperview() }
}
/// Creates one pill view per segment string and adds them to the stack view.
private func populateTags(segments: [String]) {
clearTags()
for segment in segments where !segment.isEmpty {
let pill = makePillView(text: segment)
tagsStackView.addArrangedSubview(pill)
}
}
/// Builds a rounded pill view with the given text.
private func makePillView(text: String) -> UIView {
let container = UIView()
container.backgroundColor = UIColor(rgb: 0xF1F2F4)
container.layer.cornerRadius = 13
container.clipsToBounds = true
let label = UILabel()
label.text = text
label.font = UIFont(name: "PingLCG-Regular", size: 12)
?? UIFont.systemFont(ofSize: 12)
label.textColor = UIColor(rgb: 0x00111B)
label.numberOfLines = 1
label.translatesAutoresizingMaskIntoConstraints = false
container.addSubview(label)
container.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
label.topAnchor.constraint(equalTo: container.topAnchor, constant: 6),
label.bottomAnchor.constraint(equalTo: container.bottomAnchor, constant: -6),
label.leadingAnchor.constraint(equalTo: container.leadingAnchor, constant: 8),
label.trailingAnchor.constraint(equalTo: container.trailingAnchor, constant: -8)
])
return container
}
}