Created
March 31, 2021 12:01
-
-
Save ablyGurjitSingh/4b30668de6956f8a619af2817d0c1568 to your computer and use it in GitHub Desktop.
Swift System Italic font with weights Helper.
This file contains hidden or 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 { | |
class func italicSystemFont(ofSize size: CGFloat, weight: UIFont.Weight = .regular)-> UIFont { | |
let font = UIFont.systemFont(ofSize: size, weight: weight) | |
switch weight { | |
case .ultraLight, .light, .thin, .regular: | |
return font.withTraits(.traitItalic, ofSize: size) | |
case .medium, .semibold, .bold, .heavy, .black: | |
return font.withTraits(.traitBold, .traitItalic, ofSize: size) | |
default: | |
return UIFont.italicSystemFont(ofSize: size) | |
} | |
} | |
func withTraits(_ traits: UIFontDescriptor.SymbolicTraits..., ofSize size: CGFloat) -> UIFont { | |
let descriptor = self.fontDescriptor | |
.withSymbolicTraits(UIFontDescriptor.SymbolicTraits(traits)) | |
return UIFont(descriptor: descriptor!, size: size) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment