Created
July 27, 2021 18:17
-
-
Save soffes/0059e32e39707e967941db1e9ca0d7ad to your computer and use it in GitHub Desktop.
Monospaced numbers in iOS 15 beta 4
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
import UIKit | |
extension UIFont { | |
public func withMonospacedNumbers() -> Self { | |
let monospacedFeature: [UIFontDescriptor.FeatureKey: Any] | |
if #available(iOS 15.0, *) { | |
monospacedFeature = [ | |
.type: kNumberSpacingType, | |
.selector: kMonospacedNumbersSelector | |
] | |
} else { | |
monospacedFeature = [ | |
.featureIdentifier: kNumberSpacingType, | |
.typeIdentifier: kMonospacedNumbersSelector | |
] | |
} | |
let descriptor = fontDescriptor.addingAttributes([ | |
.featureSettings: [monospacedFeature] | |
]) | |
return Self(descriptor: descriptor, size: 0) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment