Last active
July 7, 2021 11:00
-
-
Save nkukushkin/e0b874e3c5de5e245e68ca1dd4782757 to your computer and use it in GitHub Desktop.
Extension to generate fonts with monospaced numbers feature enabled
This file contains hidden or 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
import UIKit | |
extension UIFont { | |
var withMonospacedDigits: UIFont { | |
let featureSettings = [ | |
UIFontDescriptor.FeatureKey.featureIdentifier: kNumberSpacingType, | |
UIFontDescriptor.FeatureKey.typeIdentifier: kMonospacedNumbersSelector | |
] | |
let descriptorAttributes = [ | |
UIFontDescriptor.AttributeName.featureSettings: featureSettings | |
] | |
let newDescriptor = fontDescriptor.addingAttributes(descriptorAttributes) | |
return UIFont(descriptor: newDescriptor, size: 0) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment