Last active
April 9, 2022 18:43
-
-
Save juliensagot/8fc3e2e6b5ad1e14b3ecb394a417b010 to your computer and use it in GitHub Desktop.
Get UIFont with smallCaps feature (Swift 5.6, Xcode 13.3)
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
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