Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- extension UIFont {
- var monospacedDigitFont: UIFont {
- let oldFontDescriptor = fontDescriptor
- let newFontDescriptor = oldFontDescriptor.monospacedDigitFontDescriptor
- return UIFont(descriptor: newFontDescriptor, size: 0)
- }
- }
- private extension UIFontDescriptor {
- var monospacedDigitFontDescriptor: UIFontDescriptor {
- let fontDescriptorFeatureSettings = [[UIFontDescriptor.FeatureKey.featureIdentifier: kNumberSpacingType, UIFontDescriptor.FeatureKey.typeIdentifier: kMonospacedNumbersSelector]]
- let fontDescriptorAttributes = [UIFontDescriptor.AttributeName.featureSettings: fontDescriptorFeatureSettings]
- let fontDescriptor = self.addingAttributes(fontDescriptorAttributes)
- return fontDescriptor
- }
- }
Add Comment
Please, Sign In to add comment