Created
September 28, 2019 22:46
-
-
Save standinga/b5a798fea61621a799a1abbe2c1e751e to your computer and use it in GitHub Desktop.
UIFont extension for monospaced font.
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 { | |
static func monospacedFont(at size: CGFloat) -> UIFont{ | |
let bodyFontDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: UIFont.TextStyle.body) | |
let bodyMonospacedNumbersFontDescriptor = bodyFontDescriptor.addingAttributes( | |
[ | |
UIFontDescriptor.AttributeName.featureSettings: [ | |
[ | |
UIFontDescriptor.FeatureKey.featureIdentifier: kNumberSpacingType, | |
UIFontDescriptor.FeatureKey.typeIdentifier: kMonospacedNumbersSelector | |
] | |
] | |
]) | |
return UIFont(descriptor: bodyMonospacedNumbersFontDescriptor, size: size) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment