【发布时间】:2016-04-06 21:36:49
【问题描述】:
我的 Xcode 7、iOS 9 目标项目中包含自定义字体。我想让字体等宽。我试过了,但没有用:
let originalFont = UIFont(name: "My Custom Font", size: 18)
let originalFontDescriptor = originalFont!.fontDescriptor()
let fontDescriptorFeatureSettings = [
[
UIFontFeatureTypeIdentifierKey: kNumberSpacingType,
UIFontFeatureSelectorIdentifierKey: kMonospacedNumbersSelector
]
]
let fontDescriptorAttributes = [UIFontDescriptorFeatureSettingsAttribute: fontDescriptorFeatureSettings]
let fontDescriptor = originalFontDescriptor.fontDescriptorByAddingAttributes(fontDescriptorAttributes)
let font = UIFont(descriptor: fontDescriptor, size: 0)
topLabel.font = font
无论有没有上述代码,标签都会以适当的自定义字体显示。只是上面的代码没有做任何事情。
【问题讨论】:
-
代码看起来可以工作。会不会是字体设置的位置不对?你在哪里做这个?
-
这就是我要去的地方。如何获取字体设置的位置?
-
我不认为非等宽字体可以简单地用作等宽字体。字体要么是等宽的,要么不是。
标签: ios fonts core-text monospace