Skip to content

Commit

Permalink
폰트 DS 개선
Browse files Browse the repository at this point in the history
  • Loading branch information
devMinseok committed Aug 10, 2024
1 parent c8cd82f commit 279d483
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import DesignSystem

struct FontDetailView: View {
var body: some View {
VStack(alignment: .leading, spacing: 10) {
VStack(alignment: .leading, spacing: .zero) {
Text("Time")
.font(Typography.time)
Text("Header1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension BoxButtonStyleSize {
}
}

var font: Font {
var font: Typography {
switch self {
case .large:
Typography.header5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension TextButtonStyleSize {
}
}

var font: Font {
var font: Typography {
switch self {
case .large:
Typography.header5
Expand Down
157 changes: 157 additions & 0 deletions Projects/Shared/DesignSystem/Sources/Font/Typography.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
//
// Typography.swift
// DesignSystem
//
// Created by devMinseok on 8/5/24.
// Copyright © 2024 PomoNyang. All rights reserved.
//

import SwiftUI

public enum Typography {
case time
case header1
case header2
case header3
case header4
case header5
case bodySB
case bodyR
case subBodySB
case subBodyR
case captionSB
case captionR
}

extension Typography {
/// swiftui font
var font: Font {
return fontWeight.swiftUIFont(size: fontSize)
}

/// 폰트 line height
var lineHeight: CGFloat {
switch self {
case .time:
return 77
case .header1:
return 58
case .header2:
return 41
case .header3:
return 28
case .header4:
return 25
case .header5:
return 22
case .bodySB:
return 22
case .bodyR:
return 22
case .subBodySB:
return 21
case .subBodyR:
return 21
case .captionSB:
return 16
case .captionR:
return 16
}
}

/// 폰트 고유 line height
var inherentLineHeight: CGFloat {
// swiftui의 Font는 고유 lineHeight를 못가져오기에 UIFont에서 가져옴
return fontWeight.font(size: fontSize).lineHeight
}

/// 폰트 letter spacing
var letterSpacing: CGFloat {
switch self {
case .time:
return -1.28
case .header1:
return -0.96
case .header2:
return -0.68
case .header3:
return -0.48
case .header4:
return -0.4
case .header5:
return -0.36
case .bodySB:
return -0.32
case .bodyR:
return -0.32
case .subBodySB:
return -0.28
case .subBodyR:
return -0.28
case .captionSB:
return -0.12
case .captionR:
return -0.12
}
}

/// 폰트 size
private var fontSize: CGFloat {
switch self {
case .time:
return 64
case .header1:
return 48
case .header2:
return 34
case .header3:
return 24
case .header4:
return 20
case .header5:
return 18
case .bodySB:
return 16
case .bodyR:
return 16
case .subBodySB:
return 14
case .subBodyR:
return 14
case .captionSB:
return 12
case .captionR:
return 12
}
}

/// 폰트 weight
private var fontWeight: DesignSystemFontConvertible {
switch self {
case .time:
return DesignSystemFontFamily.Pretendard.bold
case .header1:
return DesignSystemFontFamily.Pretendard.bold
case .header2:
return DesignSystemFontFamily.Pretendard.bold
case .header3:
return DesignSystemFontFamily.Pretendard.bold
case .header4:
return DesignSystemFontFamily.Pretendard.semiBold
case .header5:
return DesignSystemFontFamily.Pretendard.semiBold
case .bodySB:
return DesignSystemFontFamily.Pretendard.semiBold
case .bodyR:
return DesignSystemFontFamily.Pretendard.regular
case .subBodySB:
return DesignSystemFontFamily.Pretendard.semiBold
case .subBodyR:
return DesignSystemFontFamily.Pretendard.regular
case .captionSB:
return DesignSystemFontFamily.Pretendard.semiBold
case .captionR:
return DesignSystemFontFamily.Pretendard.regular
}
}
}
19 changes: 19 additions & 0 deletions Projects/Shared/DesignSystem/Sources/Font/View+Typography.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// View+Typography.swift
// DesignSystem
//
// Created by devMinseok on 8/10/24.
// Copyright © 2024 PomoNyang. All rights reserved.
//

import SwiftUI

extension View {
public func font(_ typography: Typography) -> some View {
return self
.font(typography.font)
.lineSpacing(typography.lineHeight - typography.inherentLineHeight)
.kerning(typography.letterSpacing)
.padding(.vertical, (typography.lineHeight - typography.inherentLineHeight) / 2)
}
}
24 changes: 0 additions & 24 deletions Projects/Shared/DesignSystem/Sources/Typography.swift

This file was deleted.

0 comments on commit 279d483

Please sign in to comment.