Skip to content

Instantly share code, notes, and snippets.

@krzyzanowskim
Last active October 20, 2020 18:32
Show Gist options
  • Save krzyzanowskim/e986890689e4b2f980d96be07de365f8 to your computer and use it in GitHub Desktop.
Save krzyzanowskim/e986890689e4b2f980d96be07de365f8 to your computer and use it in GitHub Desktop.
Private "NSCTFontUIUsageAttribute" overwrites public "NSFontFamilyAttribute" attribute πŸ™ƒπŸ˜Œ if both set.
// https://twitter.com/krzyzanowskim/status/1142800558480351232
// Private "NSCTFontUIUsageAttribute" overwrites public "NSFontFamilyAttribute" attribute πŸ™ƒπŸ˜Œ if both set.
extension UIFontDescriptor.AttributeName {
static let fontUIUsageAttribute = UIFontDescriptor.AttributeName.init(rawValue: "NSCTFontUIUsageAttribute")
}
extension UIFontDescriptor {
class func preferredFontDescriptor(withTextStyle style: UIFont.TextStyle, family: String) -> UIFontDescriptor {
let preferredFontDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: style).withFamily(family)
let finalAttributes = preferredFontDescriptor.fontAttributes.filter({ $0.key != .fontUIUsageAttribute })
return UIFontDescriptor(fontAttributes: finalAttributes)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment