Last active
January 3, 2017 22:54
-
-
Save sauvikatinnofied/fe52ec3144f643a6fa0eaa86bf769b48 to your computer and use it in GitHub Desktop.
MediumBlogPost_FontHandling_Gist_5
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 Font { | |
var instance: UIFont { | |
var instanceFont: UIFont! | |
switch type { | |
case .custom(let fontName): | |
guard let font = UIFont(name: fontName, size: CGFloat(size.value)) else { | |
fatalError("\(fontName) font is not installed, make sure it is added in Info.plist and logged with Utility.logAllAvailableFonts()") | |
} | |
instanceFont = font | |
case .installed(let fontName): | |
guard let font = UIFont(name: fontName.rawValue, size: CGFloat(size.value)) else { | |
fatalError("\(fontName.rawValue) font is not installed, make sure it is added in Info.plist and logged with Utility.logAllAvailableFonts()") | |
} | |
instanceFont = font | |
case .system: | |
instanceFont = UIFont.systemFont(ofSize: CGFloat(size.value)) | |
case .systemBold: | |
instanceFont = UIFont.boldSystemFont(ofSize: CGFloat(size.value)) | |
case .systemItatic: | |
instanceFont = UIFont.italicSystemFont(ofSize: CGFloat(size.value)) | |
case .systemWeighted(let weight): | |
instanceFont = UIFont.systemFont(ofSize: CGFloat(size.value), | |
weight: CGFloat(weight)) | |
case .monoSpacedDigit(let size, let weight): | |
instanceFont = UIFont.monospacedDigitSystemFont(ofSize: CGFloat(size), | |
weight: CGFloat(weight)) | |
} | |
return instanceFont | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment