SwiftUI テキストで分母が 9 より大きい分数を表現しようとしています。
個々の要素を使用してオフセットを適用することでこれを実装できますが、分数が動的に変化するため、少し面倒です。
attributedText を使用してこれを行う方法はありますか?
非推奨のメソッドを含む UIFont 拡張機能に出会い、SwiftUI で使用できる同様のものがあるかどうか疑問に思いました。
extension UIFont {
static func fractionFont(ofSize pointSize: CGFloat) -> UIFont {
let systemFontDesc = UIFont.systemFont(ofSize: pointSize).fontDescriptor
let fractionFontDesc = systemFontDesc.addingAttributes(
[
UIFontDescriptor.AttributeName.featureSettings: [
[
UIFontDescriptor.FeatureKey.featureIdentifier: kFractionsType,
UIFontDescriptor.FeatureKey.typeIdentifier: kDiagonalFractionsSelector,
], ]
] )
return UIFont(descriptor: fractionFontDesc, size:pointSize)
}
}