[iOS] Custom Font μΆ”κ°€

YounΒ·2022λ…„ 3μ›” 17일
0

iOS

λͺ©λ‘ 보기
1/4
post-thumbnail

πŸŽƒ 폰트 μΆ”κ°€ν•˜κΈ°

1. 폰트 파일 import

  • .ttf .otf 지원
  • .wotf 파일 인식 ❌
  • Add to targets μ—μ„œ ν”„λ‘œμ νŠΈ λ°˜λ“œμ‹œ 체크
  • 디렉토리 상관없이 인식가λŠ₯, μ›ν•˜λŠ” κ²½λ‘œμ— λ„£μ–΄μ£ΌκΈ°

2. info.plist μΆ”κ°€

  • Info.plist > Information Property List > Fonts provided by application
  • 파일의 ν™•μž₯자λ₯Ό ν¬ν•¨ν•˜μ—¬ 파일λͺ… μ •μ˜

πŸŽƒ 폰트 μ‚¬μš©ν•˜κΈ°

1. μ½”λ“œ

    public enum BalooBhai2Type: String {
        case semibold = "-SemiBold"
        case regular = "Regular"
        case extraBold = "-ExtraBold"
        case bold = "-Bold"
        case medium = "-Medium"
    }

    static func BalooBhai2(_ type: BalooBhai2Type = .regular, size: CGFloat = UIFont.systemFontSize) -> UIFont {
        return UIFont(name: "BalooBhai2\(type.rawValue)", size: size)!
    }
    static func Jua(size: CGFloat = UIFont.systemFontSize) -> UIFont {
        
        return UIFont(name: "Jua-Regular", size: size)!
    }
    
    numberLabel.font = UIFont.BalooBhai2(.bold, size: 16.0)

πŸ’‘ μœ„ λ°©λ²•μœΌλ‘œ 적용이 μ•ˆλ  λ•Œ SceneDelegate.swift의 willConnectTo ν•¨μˆ˜μ—

for fontFamily in UIFont.familyNames {
    for fontName in UIFont.fontNames(forFamilyName: fontFamily) {
        print(fontName)
    }
}

μ‹€μ œ 파일λͺ…κ³Ό λ‹€λ₯Έ 폰트λͺ…이 μ μš©λ˜μ–΄ μžˆμ„ 수 μžˆμœΌλ―€λ‘œ ν™•μΈν•΄μ„œ ν•΄λ‹Ή 폰트λͺ…μœΌλ‘œ μ½”λ“œλ₯Ό μž‘μ„±ν•΄μ£Όλ©΄ 됨

2. μŠ€ν† λ¦¬λ³΄λ“œ

profile
youn

0개의 λŒ“κΈ€