如何找到 UIFontFeatureTypeIdentifierKey 的不同键?
How to find the different keys for UIFontFeatureTypeIdentifierKey?
我正在使用 New Font Features at WWDC 2015:
中的这个很棒的代码
import UIKit
let pointSize : CGFloat = 60.0
let systemFontDesc = UIFont.systemFont(ofSize: pointSize,
weight: UIFontWeightLight).fontDescriptor
let fractionFontDesc = systemFontDesc.addingAttributes(
[
UIFontDescriptorFeatureSettingsAttribute: [
[
UIFontFeatureTypeIdentifierKey: kFractionsType,
UIFontFeatureSelectorIdentifierKey: kDiagonalFractionsSelector,
],
]
] )
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 100))
label.font = UIFont(descriptor: fractionFontDesc, size:pointSize)
label.text = "12/48"
WWDC 视频展示了 UIFontDescriptorFeatureSettingsAttribute 的其他用途,例如 superiors (e = mc²)
但是解锁其他属性的钥匙是什么?
UIFontDescriptorFeatureSettingsAttribute 的文档页面只是说它是一个包含 UIFontFeatureTypeIdentifierKey 和 UIFontFeatureSelectorIdentifierKey 的字典数组。
这两个键的文档 (type and selector) 只是说它们是 NSNumber。
对于分数,类型是 kFractionsType,选择器是 kDiagonalFractionsSelector
如何找到其他可用功能的密钥?
Core Text 将为您列出字体的隐藏功能:
let desc = UIFontDescriptor(name: "Didot", size: 20) as CTFontDescriptor
let f = CTFontCreateWithFontDescriptor(desc,0,nil)
let arr = CTFontCopyFeatures(f)
print(arr as Any)
对于具有神奇名称的功能,您必须查看 SFNTLayoutTypes.h header.
我正在使用 New Font Features at WWDC 2015:
中的这个很棒的代码import UIKit
let pointSize : CGFloat = 60.0
let systemFontDesc = UIFont.systemFont(ofSize: pointSize,
weight: UIFontWeightLight).fontDescriptor
let fractionFontDesc = systemFontDesc.addingAttributes(
[
UIFontDescriptorFeatureSettingsAttribute: [
[
UIFontFeatureTypeIdentifierKey: kFractionsType,
UIFontFeatureSelectorIdentifierKey: kDiagonalFractionsSelector,
],
]
] )
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 100))
label.font = UIFont(descriptor: fractionFontDesc, size:pointSize)
label.text = "12/48"
WWDC 视频展示了 UIFontDescriptorFeatureSettingsAttribute 的其他用途,例如 superiors (e = mc²)
但是解锁其他属性的钥匙是什么?
UIFontDescriptorFeatureSettingsAttribute 的文档页面只是说它是一个包含 UIFontFeatureTypeIdentifierKey 和 UIFontFeatureSelectorIdentifierKey 的字典数组。
这两个键的文档 (type and selector) 只是说它们是 NSNumber。
对于分数,类型是 kFractionsType,选择器是 kDiagonalFractionsSelector
如何找到其他可用功能的密钥?
Core Text 将为您列出字体的隐藏功能:
let desc = UIFontDescriptor(name: "Didot", size: 20) as CTFontDescriptor
let f = CTFontCreateWithFontDescriptor(desc,0,nil)
let arr = CTFontCopyFeatures(f)
print(arr as Any)
对于具有神奇名称的功能,您必须查看 SFNTLayoutTypes.h header.