I have a stopwatch feature in my app that uses a centered attributed UILabel
with a proportionally spaced font to render time. At every time increment the width
For future readers:
This is how to enable monospaced numbers on iOS 9 with San Francisco:
let originalFont = UIFont.systemFontOfSize(17)
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)
Edit:
Also available on GitHub: https://github.com/salutis/swift-font-monospaced-digits