[UIFont] Custom 폰트가 안먹을 때, fontName을 확인해보자
[iOS | Swift] Custom Font 적용하기(+ 앱 내 폰트 변경 기능)
SceneDelegate > scene(_ scene: UIScene, willConnectTo…) method 에 아래의 코드를 추가
// 폰트 체크 하기
UIFont.familyNames.sorted().forEach { familyName in
print("*** \\(familyName) ***")
UIFont.fontNames(forFamilyName: familyName).forEach { fontName in
print("\\(fontName)")
}
print("---------------------")
}
NotoSansKR 기준으로
family font 는 Noto Sans KR
fontName은 NotoSansKR-Regular
이런식으로 -로 연결되어있다!
extension UIFont {
public enum NotoType: String {
case Regular = "Regular"
case Medium = "Medium"
case Bold = "Bold"
case Light = "Light"
}
public enum CommonType {
case regular
case medium
case bold
case light
}
static func noto(_ type: NotoType = .Regular, size: CGFloat = UIFont.systemFontSize) -> UIFont {
return UIFont(name: "NotoSansKR-\\(type.rawValue)", size: size)!
}
var isBold: Bool {
return fontDescriptor.symbolicTraits.contains(.traitBold)
}
var isItalic: Bool {
return fontDescriptor.symbolicTraits.contains(.traitItalic)
}
public func commonToNotoSans(type: CommonType) -> NotoType {
switch type {
case .regular:
return .Regular
case .medium:
return .Medium
case .bold:
return .Bold
case .light:
return .Light
}
}
}