Skip to content

Instantly share code, notes, and snippets.

@samuel-mellert
Created June 26, 2015 15:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samuel-mellert/a0419641895ff4c2ba82 to your computer and use it in GitHub Desktop.
Save samuel-mellert/a0419641895ff4c2ba82 to your computer and use it in GitHub Desktop.
extension UIFont {
static func monospacedDigitsSystemFontOfSize(fontSize: CGFloat, weight: CGFloat) -> UIFont {
let originalFontDescriptor = UIFont.systemFontOfSize(fontSize, weight: weight).fontDescriptor()
let fontDescriptorFeatureSettings = [
[
UIFontFeatureTypeIdentifierKey: kNumberSpacingType,
UIFontFeatureSelectorIdentifierKey: kMonospacedNumbersSelector
]
]
let fontDescriptorAttributes = [UIFontDescriptorFeatureSettingsAttribute: fontDescriptorFeatureSettings]
let fontDescriptor = originalFontDescriptor.fontDescriptorByAddingAttributes(fontDescriptorAttributes)
return UIFont(descriptor: fontDescriptor, size: 0)
}
}
@samuel-mellert
Copy link
Author

Ah, you are right. They seem to have fixed this with beta 4! Great to know. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment