Skip to content

Commit 4e70736

Browse files
committed
fix: 영어로 사용 시 월요일, 수요일이 셀 보다 크기가 커 '...' 으로 보이는 이슈 해결
1 parent 398d088 commit 4e70736

1 file changed

Lines changed: 39 additions & 17 deletions

File tree

DevLog/UI/Profile/ProfileHeatmapView.swift

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,32 +52,54 @@ struct ProfileHeatmapView: View {
5252
6: String(localized: "profile_weekday_fri")
5353
]
5454
let orderedWeekdays = Array(1...7)
55+
let labelFontSize = smallestWeekdayLabelFontSize(
56+
labels: Array(labels.values),
57+
layout: layout
58+
)
5559

5660
VStack(alignment: .leading, spacing: layout.cellSpacing) {
5761
ForEach(orderedWeekdays, id: \.self) { weekday in
58-
Group {
59-
if let label = labels[weekday] {
60-
Text(label)
61-
.font(.caption2)
62-
.foregroundStyle(.secondary)
63-
.frame(
64-
width: layout.cellSize,
65-
height: layout.cellSize,
66-
alignment: .leading
67-
)
68-
} else {
69-
Color.clear
70-
.frame(
71-
width: layout.cellSize,
72-
height: layout.cellSize
73-
)
74-
}
62+
if let label = labels[weekday] {
63+
Text(label)
64+
.font(.system(size: labelFontSize))
65+
.allowsTightening(true)
66+
.foregroundStyle(.secondary)
67+
.frame(
68+
width: layout.cellSize,
69+
height: layout.cellSize,
70+
alignment: .leading
71+
)
72+
.onAppear {
73+
print(labelFontSize)
74+
}
75+
} else {
76+
Color.clear
77+
.frame(
78+
width: layout.cellSize,
79+
height: layout.cellSize
80+
)
7581
}
7682
}
7783
}
7884
.padding(.top, layout.weekdayTopPadding)
7985
}
8086

87+
private func smallestWeekdayLabelFontSize(labels: [String], layout: ProfileHeatmapLayout) -> CGFloat {
88+
let captionFont = UIFont.preferredFont(forTextStyle: .caption2)
89+
let availableWidth = max(layout.cellSize, 1)
90+
91+
let fittedSizes = labels.map { label in
92+
let textWidth = max(
93+
(label as NSString).size(withAttributes: [.font: captionFont]).width,
94+
1
95+
)
96+
let widthRatio = availableWidth / textWidth
97+
return captionFont.pointSize * min(widthRatio, 1)
98+
}
99+
100+
return max((fittedSizes.min() ?? captionFont.pointSize).rounded(.down), 1)
101+
}
102+
81103
private var availableWidth: CGFloat {
82104
// ProfileView의 바깥 가로 패딩(16)과 히트맵 카드 내부 패딩(12)을 합한 값
83105
let horizontalPadding: CGFloat = 16 + 12

0 commit comments

Comments
 (0)