Skip to content

Instantly share code, notes, and snippets.

@nkukushkin
Last active July 7, 2021 11:00
Show Gist options
  • Save nkukushkin/e0b874e3c5de5e245e68ca1dd4782757 to your computer and use it in GitHub Desktop.
Save nkukushkin/e0b874e3c5de5e245e68ca1dd4782757 to your computer and use it in GitHub Desktop.
Extension to generate fonts with monospaced numbers feature enabled
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