Last active
June 7, 2018 11:21
-
-
Save dobaduc/a246e490813e50aade04 to your computer and use it in GitHub Desktop.
Swift - Detect font traits examples (For Bold and Italic)
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 isBold: Bool { | |
return (fontDescriptor().symbolicTraits.rawValue & UIFontDescriptorSymbolicTraits.TraitBold.rawValue) > 0 | |
} | |
var isItalic: Bool { | |
return (fontDescriptor().symbolicTraits.rawValue & UIFontDescriptorSymbolicTraits.TraitItalic.rawValue) > 0 | |
} | |
} |
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
Swift 2.0: return fontDescriptor().symbolicTraits.contains(.TraitBold)
:-)