Skip to content

Commit a963a0f

Browse files
authored
[NL-57]: 번호 상세 화면 UI 구현 마무리 (#36)
* [NL-57]: 예상 당첨금 영역 삭제 * [NL-57]: 제외할 번호 영역 캐러셀로 수정 * [NL-57]: 번호 상세 화면 BaseViewController 적용 * [NL-57]: 번호 상세 화면 Footer 영역 구현 * [NL-57]: 툴팁 UI 구현
1 parent eed1016 commit a963a0f

File tree

10 files changed

+356
-59
lines changed

10 files changed

+356
-59
lines changed

Common/Base/Sources/BaseViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ open class BaseViewController: UIViewController {
4343
}
4444

4545
private func setupNavigationBar() {
46+
navigationController?.setNavigationBarHidden(true, animated: false)
4647
view.addSubview(navigationBar)
4748
navigationBar.snp.makeConstraints { make in
4849
make.top.equalTo(view.snp.top)
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "Arrow.svg",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
}
12+
}

Feature/Home/Sources/RecommendationDetail/AvoidNumberCollectionViewCell.swift

Lines changed: 71 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ struct AvoidNumberCollectionViewCellModel: RecommendationDetailCellModel {
1414
}
1515

1616
final class AvoidNumberCollectionViewCell: UICollectionViewCell {
17-
17+
18+
private enum Constant {
19+
static let itemHeight: CGFloat = 122
20+
static let spacing: CGFloat = 6
21+
}
22+
1823
private lazy var headerTitleLabel = UILabel().then {
1924
$0.style = Typography.Body_14_B
2025
$0.textColor = STColors.gray2.color
@@ -36,52 +41,96 @@ final class AvoidNumberCollectionViewCell: UICollectionViewCell {
3641
$0.numberOfLines = .zero
3742
$0.styledText = "혹시 다른 번호도 고민 중이라면,\n이 번호들은 피해주세요!"
3843
}
39-
private lazy var numberCardStackView = UIStackView().then {
40-
$0.spacing = 6
41-
$0.axis = .horizontal
42-
$0.distribution = .fillEqually
44+
private lazy var collectionView = UICollectionView(
45+
frame: .zero,
46+
collectionViewLayout: createCollectionViewLayout()
47+
).then {
48+
$0.backgroundColor = .clear
49+
$0.showsHorizontalScrollIndicator = false
50+
$0.dataSource = self
51+
$0.register(
52+
NumberCardItemCollectionViewCell.self,
53+
forCellWithReuseIdentifier: NumberCardItemCollectionViewCell.typeName
54+
)
4355
}
44-
56+
private var cellModel: AvoidNumberCollectionViewCellModel?
57+
58+
private func createCollectionViewLayout() -> UICollectionViewLayout {
59+
let itemSize = NSCollectionLayoutSize(
60+
widthDimension: .fractionalWidth(0.5),
61+
heightDimension: .absolute(Constant.itemHeight)
62+
)
63+
let item = NSCollectionLayoutItem(layoutSize: itemSize)
64+
65+
let groupSize = NSCollectionLayoutSize(
66+
widthDimension: .fractionalWidth(1.0),
67+
heightDimension: .absolute(Constant.itemHeight)
68+
)
69+
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item])
70+
group.interItemSpacing = .fixed(Constant.spacing)
71+
72+
let section = NSCollectionLayoutSection(group: group)
73+
section.interGroupSpacing = Constant.spacing
74+
section.orthogonalScrollingBehavior = .continuous
75+
76+
return UICollectionViewCompositionalLayout(section: section)
77+
}
78+
4579
override init(frame: CGRect) {
4680
super.init(frame: frame)
4781
setupUI()
4882
}
49-
83+
5084
required init?(coder: NSCoder) {
5185
fatalError("init(coder:) has not been implemented")
5286
}
53-
87+
5488
private func setupUI() {
5589
contentView.backgroundColor = .clear
56-
90+
5791
contentView.addSubview(headerTitleLabel)
5892
headerTitleLabel.snp.makeConstraints { make in
5993
make.top.leading.trailing.equalToSuperview()
6094
}
61-
95+
6296
contentView.addSubview(contentStackView)
6397
contentStackView.snp.makeConstraints { make in
6498
make.top.equalTo(headerTitleLabel.snp.bottom).offset(8)
6599
make.leading.trailing.bottom.equalToSuperview()
66100
}
67-
101+
68102
contentStackView.addArrangedSubview(descriptionLabel)
69103
descriptionLabel.snp.makeConstraints { make in
70104
make.height.equalTo(42)
71105
}
72-
73-
contentStackView.addArrangedSubview(numberCardStackView)
106+
107+
contentStackView.addArrangedSubview(collectionView)
108+
collectionView.snp.makeConstraints { make in
109+
make.height.equalTo(Constant.itemHeight)
110+
}
74111
}
75-
112+
76113
func update(with model: AvoidNumberCollectionViewCellModel) {
77-
numberCardStackView.arrangedSubviews.forEach {
78-
$0.removeFromSuperview()
79-
}
80-
model.items.forEach { item in
81-
let numberCardView = NumberCardItemView()
82-
numberCardView.update(with: item)
83-
numberCardStackView.addArrangedSubview(numberCardView)
114+
cellModel = model
115+
collectionView.reloadData()
116+
}
117+
}
118+
119+
extension AvoidNumberCollectionViewCell: UICollectionViewDataSource {
120+
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
121+
return cellModel?.items.count ?? .zero
122+
}
123+
124+
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
125+
let cell = collectionView.dequeueReusableCell(
126+
withReuseIdentifier: NumberCardItemCollectionViewCell.typeName,
127+
for: indexPath
128+
)
129+
if let cell = cell as? NumberCardItemCollectionViewCell,
130+
let item = cellModel?.items[safe: indexPath.item] {
131+
cell.update(with: item)
84132
}
133+
return cell
85134
}
86135
}
87136

@@ -91,6 +140,7 @@ final class AvoidNumberCollectionViewCell: UICollectionViewCell {
91140
items: [
92141
.init(title: "수(水) 기운과\n상충하는 숫자", numbers: [9, 11, 18]),
93142
.init(title: "최근 100회 동안\n거의 안 나온 숫자", numbers: [24, 33]),
143+
.init(title: "숫자", numbers: [44]),
94144
]
95145
)
96146
let cell = AvoidNumberCollectionViewCell()

Feature/Home/Sources/RecommendationDetail/NumberCardItemView.swift renamed to Feature/Home/Sources/RecommendationDetail/NumberCardItemCollectionViewCell.swift

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
//
2-
// NumberCardItemView.swift
2+
// NumberCardItemCollectionViewCell.swift
33
// Home
44
//
55
// Created by ttozzi on 8/9/25.
66
//
77

8+
import Base
89
import DesignSystem
910
import UIKit
1011

@@ -13,8 +14,8 @@ struct NumberCardItem {
1314
let numbers: [Int]
1415
}
1516

16-
final class NumberCardItemView: UIView {
17-
17+
final class NumberCardItemCollectionViewCell: BaseCollectionViewCell {
18+
1819
private lazy var contentStackView = UIStackView().then {
1920
$0.spacing = 20
2021
$0.axis = .vertical
@@ -28,39 +29,46 @@ final class NumberCardItemView: UIView {
2829
private lazy var numberBallStackView = UIStackView().then {
2930
$0.spacing = 8
3031
$0.axis = .horizontal
32+
$0.alignment = .bottom
3133
}
32-
34+
3335
override init(frame: CGRect) {
3436
super.init(frame: frame)
3537
setupUI()
3638
}
37-
39+
3840
required init?(coder: NSCoder) {
3941
fatalError("init(coder:) has not been implemented")
4042
}
41-
43+
4244
private func setupUI() {
43-
backgroundColor = STColors.gray9.color
44-
clipsToBounds = true
45-
layer.cornerRadius = 10
46-
47-
addSubview(contentStackView)
45+
contentView.backgroundColor = STColors.gray9.color
46+
contentView.clipsToBounds = true
47+
contentView.layer.cornerRadius = 10
48+
49+
contentView.addSubview(contentStackView)
4850
contentStackView.snp.makeConstraints { make in
4951
make.edges.equalToSuperview().inset(16)
5052
}
51-
53+
5254
contentStackView.addArrangedSubview(titleLabel)
53-
55+
5456
contentStackView.addArrangedSubview(numberBallStackView)
57+
numberBallStackView.snp.makeConstraints { make in
58+
make.height.greaterThanOrEqualTo(28)
59+
}
5560
}
56-
61+
5762
func update(with item: NumberCardItem) {
5863
titleLabel.styledText = item.title
5964
numberBallStackView.arrangedSubviews.forEach {
6065
$0.removeFromSuperview()
6166
}
6267
item.numbers.forEach { number in
6368
let ball = Ball()
69+
ball.snp.makeConstraints { make in
70+
make.size.equalTo(28)
71+
}
6472
ball.number = String(number)
6573
numberBallStackView.addArrangedSubview(ball)
6674
}
@@ -73,7 +81,11 @@ final class NumberCardItemView: UIView {
7381
title: "수(水) 기운과\n상충하는 숫자",
7482
numbers: [9, 11, 18]
7583
)
76-
let view = NumberCardItemView()
77-
view.update(with: item)
78-
return view
84+
let cell = NumberCardItemCollectionViewCell()
85+
cell.snp.makeConstraints { make in
86+
make.height.equalTo(122)
87+
make.width.equalTo(140)
88+
}
89+
cell.update(with: item)
90+
return cell
7991
}

Feature/Home/Sources/RecommendationDetail/NumberRecommendationCollectionViewCell.swift

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ struct NumberRecommendationCollectionViewCellModel: RecommendationDetailCellMode
1313
let roundText: String
1414
let title: String
1515
let numbers: [Int]
16-
let expectedPrize: String
1716
let timeUntilDraw: String // TODO: 확인 필요
1817
}
1918

@@ -43,11 +42,6 @@ final class NumberRecommendationCollectionViewCell: UICollectionViewCell {
4342
$0.axis = .horizontal
4443
$0.alignment = .center
4544
}
46-
private lazy var expectedPrizeLabel = UILabel().then {
47-
$0.style = Typography.Body_14_SB
48-
$0.textColor = STColors.gray1.color
49-
$0.textAlignment = .right
50-
}
5145
private lazy var timeUntilDrawLabel = UILabel().then {
5246
$0.style = Typography.Body_14_SB
5347
$0.textColor = STColors.gray1.color
@@ -95,14 +89,7 @@ final class NumberRecommendationCollectionViewCell: UICollectionViewCell {
9589
make.height.equalTo(1)
9690
make.width.equalToSuperview()
9791
}
98-
99-
let expectedPrizeStackView = makeTextStackView(
100-
title: "이번 주 예상 당첨금", descriptionLabel: expectedPrizeLabel)
101-
contentStackView.addArrangedSubview(expectedPrizeStackView)
102-
expectedPrizeStackView.snp.makeConstraints { make in
103-
make.width.equalToSuperview()
104-
}
105-
contentStackView.setCustomSpacing(6, after: expectedPrizeStackView)
92+
10693
let timeUntilDrawStackView = makeTextStackView(
10794
title: "추첨까지 남은 시간", descriptionLabel: timeUntilDrawLabel)
10895
contentStackView.addArrangedSubview(timeUntilDrawStackView)
@@ -122,7 +109,6 @@ final class NumberRecommendationCollectionViewCell: UICollectionViewCell {
122109
ball.number = String(number)
123110
numberBallStackView.addArrangedSubview(ball)
124111
}
125-
expectedPrizeLabel.styledText = model.expectedPrize
126112
timeUntilDrawLabel.styledText = model.timeUntilDraw
127113
}
128114

@@ -153,7 +139,6 @@ final class NumberRecommendationCollectionViewCell: UICollectionViewCell {
153139
roundText: "1181회",
154140
title: "콩떡님을 위한 로또 번호 추천",
155141
numbers: [9, 11, 18, 24, 33, 42],
156-
expectedPrize: "402,396,191원",
157142
timeUntilDraw: "6일 2시간 59분 32초"
158143
)
159144
let cell = NumberRecommendationCollectionViewCell()

0 commit comments

Comments
 (0)