Skip to content

Instantly share code, notes, and snippets.

@juliensagot
Last active April 9, 2022 18:43
Show Gist options
  • Save juliensagot/8fc3e2e6b5ad1e14b3ecb394a417b010 to your computer and use it in GitHub Desktop.
Save juliensagot/8fc3e2e6b5ad1e14b3ecb394a417b010 to your computer and use it in GitHub Desktop.
Get UIFont with smallCaps feature (Swift 5.6, Xcode 13.3)
extension UIFont {
var withSmallCaps: UIFont {
let upperCaseFeature = [
UIFontDescriptor.FeatureKey.type : kUpperCaseType,
UIFontDescriptor.FeatureKey.selector : kUpperCaseSmallCapsSelector
]
let lowerCaseFeature = [
UIFontDescriptor.FeatureKey.type : kLowerCaseType,
UIFontDescriptor.FeatureKey.selector : kLowerCaseSmallCapsSelector
]
let features = [upperCaseFeature, lowerCaseFeature]
let smallCapsDescriptor = fontDescriptor.addingAttributes([.featureSettings : features])
return UIFont(descriptor: smallCapsDescriptor, size: pointSize)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment