SwiftUI.Font如何应用UIFontDescriptor.FeatureKey.featureIdentifier?

问题描述 投票:0回答:1

A UIFont 可以很容易地通过字体描述符进行设置,例如,在SwiftUI中如何实现同样的功能?

let settings: [UIFontDescriptor.FeatureKey: Int] = [            
   .featureIdentifier: kStylisticAlternativesType,
   .typeIdentifier: 2]

let descriptor = someBaseFont.fontDescriptor.addingAttributes([.featureSettings: [settings]])
let newFont = UIFont(descriptor: descriptor, size: size)

(如何)可以在SwiftUI中实现同样的功能?

swiftui uifont uifontdescriptor
1个回答
1
投票

暂时没有直接的方法,但这里有一个解决方案。

// .. your above code
let newFont = UIFont(descriptor: descriptor, size: size)
let myFont = Font(newFont as CTFont)                       // << here !!
© www.soinside.com 2019 - 2024. All rights reserved.