# UIFont
커스텀 폰트에서 접근성 설정에 따라 다이나믹한 크기 설정
enum CustomFonts: String {
case NotoSans = "NotoSansKR"
}
enum CustomFontStyle: String {
case bold = "-Bold"
case light = "-Light"
case medium = "-Medium"
case regular = "-Regular"
case semiBold = "-SemiBold"
case thin = "-Thin"
}
enum CustomFontSize: CGFloat {
case h0 = 36.0
case h1 = 32.0
case h2 = 20.0
case h3 = 16.0
case h4 = 8.0
}
extension UIFont {
static func customFont(
font: CustomFonts,
style: CustomFontStyle,
size: CustomFontSize,
isScaled: Bool = true) -> UIFont {
let fontName: String = font.rawValue + style.rawValue
guard let font = UIFont(name: fontName, size: size.rawValue) else {
debugPrint("Font can't be loaded")
return UIFont.systemFont(ofSize: size.rawValue)
}
return isScaled ? UIFontMetrics.default.scaledFont(for: font) : font
}
}
UIFontMetrics를 사용해 적용
label.adjustsFontForContentSizeCategory = true
설정 적용 필수