gpt4 book ai didi

ios - UIFont 等宽数字+小型大写字母

转载 作者:行者123 更新时间:2023-11-30 11:14:59 26 4
gpt4 key购买 nike

我正在尝试创建一个 UIFont具有以下属性:

  • 大写小写
  • 小写小型大写字母
  • 等宽数字

我正在使用系统字体 ( San Francisco ),它支持所有这些功能。
据我所知,唯一的方法是使用多个 UIFontDescriptor .

这是我正在使用的代码:

extension UIFont {

var withSmallCaps: UIFont {
let upperCaseFeature = [
UIFontDescriptor.FeatureKey.featureIdentifier : kUpperCaseType,
UIFontDescriptor.FeatureKey.typeIdentifier : kUpperCaseSmallCapsSelector
]
let lowerCaseFeature = [
UIFontDescriptor.FeatureKey.featureIdentifier : kLowerCaseType,
UIFontDescriptor.FeatureKey.typeIdentifier : kLowerCaseSmallCapsSelector
]
let features = [upperCaseFeature, lowerCaseFeature]
let smallCapsDescriptor = self.fontDescriptor.addingAttributes([UIFontDescriptor.AttributeName.featureSettings : features])

return UIFont(descriptor: smallCapsDescriptor, size: pointSize)
}

var withMonospacedDigits: UIFont {
let monospacedDigitsFeature = [
UIFontDescriptor.FeatureKey.featureIdentifier : kNumberSpacingType,
UIFontDescriptor.FeatureKey.typeIdentifier : kMonospacedNumbersSelector
]
let monospacedDigitsDescriptor = self.fontDescriptor.addingAttributes([UIFontDescriptor.AttributeName.featureSettings : [monospacedDigitsFeature]])

return UIFont(descriptor: monospacedDigitsDescriptor, size: pointSize)
}
}

我应该能够通过这行代码获得具有前面提到的所有特征的字体:

let font = UIFont.systemFont(ofSize: 16, weight: .regular).withSmallCaps.withMonospacedDigits
// OR
let font = UIFont.monospacedDigitSystemFont(ofSize: 16, weight: .regular).withSmallCaps

但由于某些原因,它不起作用。我无法让字体在具有等宽数字的同时具有小型大写字母。

我做错了什么?

最佳答案

多亏了reference document,我明白了为什么它不起作用。链接为 @Carpsen90 .

似乎数字间距功能是独有的

如文档中所述:

Features are classified as "exclusive" and "nonexclusive." This indicates whether several different selectors within a given feature type may be selected at once. Thus, it is possible to have both common and rare ligatures turned on, whereas it is impossible to display a given fraction as simultaneously vertical and diagonal.

因此同时拥有等宽数字+小型大写字母功能是不可能的。

<小时/>

编辑:

我看错了文档。该功能的选择器是排他的。但不是全部功能。所以应该是可以的。

关于ios - UIFont 等宽数字+小型大写字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51828496/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com