Skip to content

Instantly share code, notes, and snippets.

@Marcocanc
Created March 8, 2017 16:17
Show Gist options
  • Save Marcocanc/9ffc1894743367173012b9d66e8b3ad8 to your computer and use it in GitHub Desktop.
Save Marcocanc/9ffc1894743367173012b9d66e8b3ad8 to your computer and use it in GitHub Desktop.
really hoping this will work out of the box in future versions
public extension UIFont {
public class func systemFont(ofSize fontSize: CGFloat, weight: UIFontWeight) -> UIFont {
return .systemFont(ofSize: fontSize, weight: weight.floatValue)
}
public class func monospacedDigitSystemFont(ofSize fontSize: CGFloat, weight: UIFontWeight) -> UIFont {
return .monospacedDigitSystemFont(ofSize: fontSize, weight: weight.floatValue)
}
}
public enum UIFontWeight {
case ultralight
case thin
case light
case regular
case medium
case semibold
case bold
case black
case heavy
public var floatValue: CGFloat {
switch self {
case .ultralight:
return UIFontWeightUltraLight
case .thin:
return UIFontWeightThin
case .light:
return UIFontWeightLight
case .regular:
return UIFontWeightRegular
case .medium:
return UIFontWeightMedium
case .semibold:
return UIFontWeightSemibold
case .bold:
return UIFontWeightBold
case .black:
return UIFontWeightBlack
case .heavy:
return UIFontWeightHeavy
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment