Skip to content

Instantly share code, notes, and snippets.

@sauvikatinnofied
Last active January 3, 2017 22:54
Show Gist options
  • Save sauvikatinnofied/fe52ec3144f643a6fa0eaa86bf769b48 to your computer and use it in GitHub Desktop.
Save sauvikatinnofied/fe52ec3144f643a6fa0eaa86bf769b48 to your computer and use it in GitHub Desktop.
MediumBlogPost_FontHandling_Gist_5
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