앱 언어 설정이 한국어("ko")이면 Pretendard 폰트 그 외에는 시스템 폰트하는 FontModifier 추가

This commit is contained in:
Yu Sung
2026-01-23 02:44:18 +09:00
parent 4b9cdeb824
commit 87c66136ac
2 changed files with 46 additions and 3 deletions

View File

@@ -0,0 +1,43 @@
//
// KoreanFontModifier.swift
// SodaLive
//
// Created by klaus on 1/23/26.
//
import SwiftUI
struct KoreanFontModifier: ViewModifier {
@Environment(\.locale) private var locale
let size: CGFloat
let weight: SwiftUI.Font.Weight
private func resolvedLanguageCode() -> String? {
if let raw = UserDefaults.standard.string(forKey: "app.language"),
let option = LanguageOption(rawValue: raw),
option != .system {
return option.rawValue
}
return locale.language.languageCode?.identifier
}
func body(content: Content) -> some View {
if resolvedLanguageCode() == "ko" {
let name: String = switch weight {
case .bold: "Pretendard-Bold"
case .medium: "Pretendard-Medium"
case .light: "Pretendard-Light"
default: "Pretendard-Regular"
}
content.font(.custom(name, size: size))
} else {
content.font(.system(size: size, weight: weight))
}
}
}
extension View {
func appFont(size: CGFloat, weight: SwiftUI.Font.Weight = .regular) -> some View {
self.modifier(KoreanFontModifier(size: size, weight: weight))
}
}

View File

@@ -12,7 +12,7 @@ struct TabButton: View {
let title: LocalizedStringResource let title: LocalizedStringResource
let action: () -> Void let action: () -> Void
let image: () -> String let image: () -> String
let fontName: () -> String let fontWeight: () -> SwiftUI.Font.Weight
let color: () -> Color let color: () -> Color
let width: CGFloat let width: CGFloat
@@ -21,7 +21,7 @@ struct TabButton: View {
Image(image()) Image(image())
Text(title) Text(title)
.font(.custom(fontName(), size: 10)) .appFont(size: 10, weight: fontWeight())
.foregroundColor(color()) .foregroundColor(color())
} }
.frame(width: width) .frame(width: width)
@@ -37,7 +37,7 @@ struct TabButton_Previews: PreviewProvider {
title: "라이브", title: "라이브",
action: {}, action: {},
image: { "ic_tabbar_live_selected" }, image: { "ic_tabbar_live_selected" },
fontName: { Font.bold.rawValue }, fontWeight: { .bold },
color: { Color(hex: "3bb9f1") }, color: { Color(hex: "3bb9f1") },
width: UIScreen.main.bounds.width / 4 width: UIScreen.main.bounds.width / 4
) )