Skip to content

Instantly share code, notes, and snippets.

@michaelevensen
Created September 12, 2023 12:17
Show Gist options
  • Save michaelevensen/c72133612bf2c7538df152250a970753 to your computer and use it in GitHub Desktop.
Save michaelevensen/c72133612bf2c7538df152250a970753 to your computer and use it in GitHub Desktop.
This is how you can use font features in Swift.
public static let book: Font = {
// Font features
let fontFeatureSettings: [CFDictionary] = [
[
kCTFontFeatureTypeIdentifierKey: kTypographicExtrasType,
kCTFontFeatureSelectorIdentifierKey: kSlashedZeroOnSelector
] as CFDictionary
]
// Font description
let fontDescriptor = CTFontDescriptorCreateWithAttributes([
kCTFontFeatureSettingsAttribute: fontFeatureSettings
] as CFDictionary)
let font = CTFontCreateWithName("SuisseIntl-Book" as CFString, 18, nil)
let fontWithFeatures = CTFontCreateCopyWithAttributes(font, 18, nil, fontDescriptor)
return Font(fontWithFeatures)
}()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment