NotoSansCJKkr otf 파일 폰트를 별도로 다운로드 받아 프로젝트에 첨부하고

Info.plist에 폰트 등록 후 사용해야됨.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
	<string>NotoSansCJKkr-Bold.otf</string>
	<string>NotoSansCJKkr-Black.otf</string>
	<string>NotoSansCJKkr-Medium.otf</string>
	<string>NotoSansCJKkr-Regular.otf</string>
	<string>NotoSansCJKkr-Light.otf</string>
	<string>NotoSansCJKkr-Thin.otf</string>
</array>
</plist>

 

 

https://fonts.google.com/noto/specimen/Noto+Sans+KR 

 

Noto Sans Korean - Google Fonts

Noto is a global font collection for writing in all modern and ancient languages. Noto Sans KR is an unmodulated (“sans serif”) design for the Korean language u

fonts.google.com

import UIKit

enum FontStyleNumber: Int {
    case Black = 0
    case Bold
    case Regular
    case Medium
    case Light
    case Thin
    
    var fontName: IGuidefontName {
        switch self {
        case .Black:
            return .NotoSansCJKkrBlack
        case .Bold:
            return .NotoSansCJKkrBold
        case .Regular:
            return .NotoSansCJKkrRegular
        case .Medium:
            return .NotoSansCJKkrMedium
        case .Light:
            return .NotoSansCJKkrLight
        case .Thin:
            return .NotoSansCJKkrThin
        }
    }
}

enum IGuidefontName: String, CaseIterable {
    case NotoSansCJKkrBlack = "NotoSansCJKkr-Black"
    case NotoSansCJKkrBold = "NotoSansCJKkr-Bold"
    case NotoSansCJKkrRegular = "NotoSansCJKkr-Regular"
    case NotoSansCJKkrMedium = "NotoSansCJKkr-Medium"
    case NotoSansCJKkrLight = "NotoSansCJKkr-Light"
    case NotoSansCJKkrThin = "NotoSansCJKkr-Thin"
}

extension UIFont {
    
    // 문자열 길이 사이즈
    func sizeOfString (string: String, constrainedToWidth width: Double) -> CGSize {
        
        return NSString(string: string).boundingRect(with: CGSize(width: width, height: .greatestFiniteMagnitude), options: NSStringDrawingOptions.usesLineFragmentOrigin, attributes: [NSAttributedString.Key.font: self],
            context: nil).size
    }
    
    // 비율에 맞는 폰트 사이즈 재계산
    static func resolutionfontSize(size: CGFloat) -> CGFloat {
        let bounds = UIScreen.main.bounds
        let height = bounds.size.height
        let width = bounds.size.width
                        
        let size_formatter = size / 375
        let result = width * size_formatter
        
        log(direction: .ETC, ofType: self, datas: width,height,size,size_formatter,result)
        
        return result
    }
    
    // Custom 폰트 사용 (별도 등록작업 필요)
    static func notoSansFont(forFont name: IGuidefontName, size: CGFloat, isScaledFont: Bool = false) -> UIFont {
                
        let resolution =  isScaledFont == true ? resolutionfontSize(size: size) : size
        
        guard let font = UIFont(name: name.rawValue, size: resolution) else {
            return UIFont.systemFont(ofSize: resolution)
        }
        
        return font
    }
    
    var isBold: Bool {
        return fontDescriptor.symbolicTraits.contains(.traitBold)
    }

    var isItalic: Bool {
        return fontDescriptor.symbolicTraits.contains(.traitItalic)
    }
}

+ Recent posts