Skip to content

Instantly share code, notes, and snippets.

@soffes
Created July 27, 2021 18:17
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soffes/0059e32e39707e967941db1e9ca0d7ad to your computer and use it in GitHub Desktop.
Save soffes/0059e32e39707e967941db1e9ca0d7ad to your computer and use it in GitHub Desktop.
Monospaced numbers in iOS 15 beta 4
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