Skip to content

Instantly share code, notes, and snippets.

@dobaduc
Last active June 7, 2018 11:21
Show Gist options
  • Save dobaduc/a246e490813e50aade04 to your computer and use it in GitHub Desktop.
Save dobaduc/a246e490813e50aade04 to your computer and use it in GitHub Desktop.
Swift - Detect font traits examples (For Bold and Italic)
extension UIFont {
var isBold: Bool {
return (fontDescriptor().symbolicTraits.rawValue & UIFontDescriptorSymbolicTraits.TraitBold.rawValue) > 0
}
var isItalic: Bool {
return (fontDescriptor().symbolicTraits.rawValue & UIFontDescriptorSymbolicTraits.TraitItalic.rawValue) > 0
}
}
@ar-juan
Copy link

ar-juan commented Feb 25, 2016

Swift 2.0: return fontDescriptor().symbolicTraits.contains(.TraitBold)
:-)

@MohamedElzokla
Copy link

swift 4.1 :
return (fontDescriptor.symbolicTraits.rawValue & UIFontDescriptorSymbolicTraits.traitBold.rawValue) > 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment