Created
June 26, 2015 15:09
-
-
Save samuel-mellert/a0419641895ff4c2ba82 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
FYI In Xcode 7 beta 4 I was able to get the same behavior as NSFont in the apple keynote
example: label.font = UIFont.monospacedDigitSystemFontOfSize(62, weight: UIFontWeightUltraLight)
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
Adds missing static method to UIFont, that generates a UIFont with monospaced numeral rendering (which is disabled by default when linking against iOS 9 SDK - there you'll get proportional spaced numeral rendering).