Skip to content

Instantly share code, notes, and snippets.

@cjmlgrto
Created August 13, 2019 01:45
Show Gist options
  • Save cjmlgrto/a32bc64f32a982110202182602caddf4 to your computer and use it in GitHub Desktop.
Save cjmlgrto/a32bc64f32a982110202182602caddf4 to your computer and use it in GitHub Desktop.
Tabular Fonts
import Foundation
import UIKit
extension UIFont {
static func tabularSystemFont(ofSize: CGFloat, weight: UIFont.Weight) -> UIFont {
let features = [
[
UIFontDescriptor.FeatureKey.featureIdentifier: kNumberSpacingType,
UIFontDescriptor.FeatureKey.typeIdentifier: kMonospacedNumbersSelector
]
]
let fontDescriptor = UIFont.systemFont(ofSize: ofSize, weight: weight).fontDescriptor.addingAttributes([UIFontDescriptor.AttributeName.featureSettings: features])
return UIFont(descriptor: fontDescriptor, size: ofSize)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment