시놉시스
Specifying Fonts - 어떤 폰트를 쓸 것인가?
// 시스템 폰트 반환
class func preferredFont(forTextStyle style: UIFont.TextStyle) -> UIFont
// CSS로도 사용 가능
// -apple-system- prefix가 붙어있다.
// 명시적 매칭
func matchingFontDescriptors(withMandatoryKeys mandatoryKeys: Set<UIFontDescriptor.AttributeName>?) -> [UIFontDescriptor]
// 암시적 매칭
func withSymbolicTraits(_ symbolicTraits: UIFontDescriptor.SymbolicTraits) -> UIFontDescriptor?
init(descriptor: UIFontDescriptor, size pointSize: CGFloat)
// 예제
let helveticaNeue = UIFontDescriptor(fontAttributes: [.family: "Helvetica Neue"])
let matched = helveticaNeue.matchingFontDescriptors(withMandatoryKeys: nil)
let fontDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .body)
let boldFontDescriptor = fontDescriptor.withSymbolicTraits(.traitBold)
let boldFont = UIFont(descriptor: boldFontDescriptor!, size: 0.0)
// 폰트 기능 활성화 예제
let timeFeatureSettings = [
[ UIFontDescriptor.FeatureKey.featureIdentifier: kNumberSpacingType,
UIFontDescriptor.FeatureKey.typeIdentifier: kProportionalNumbersSelector
],
[ UIFontDescriptor.FeatureKey.featureIdentifier: kCharacterAlternativesType,
UIFontDescriptor.FeatureKey.typeIdentifier: 1
]
]
let font = UIFont.systemFont(ofSize: 16)
let descriptor = font.fontDescriptor
let timeDescriptor = descriptor.addingAttributes([.featureSettings: timeFeatureSettings])
let timeFont = UIFont(descriptor: timeDescriptor, size: 0.0)
// 특정 캐릭터 제거
let font = UIFont.systemFont(ofSize: 16)
let descriptor = font.fontDescriptor
let characterSet = descriptor.object(forKey: .characterSet) as! NSMutableCharacterSet
// 눈사람 모양
characterSet.removeCharacters(in: NSMakeRange(0x2603, 1))
let snowmanRemoved = descriptor.addingAttributes([.characterSet: characterSet])
let newFont = UIFont(descriptor: snowmanRemoved, size: 0.0)
Language Tagging
Modifying fallbacks
static let cascadeList: UIFontDescriptor.AttributeName