Skip to content

Instantly share code, notes, and snippets.

@imkevinxu
Last active January 16, 2019 06:06
Show Gist options
  • Save imkevinxu/b92fa70f37e4846bcd27 to your computer and use it in GitHub Desktop.
Save imkevinxu/b92fa70f37e4846bcd27 to your computer and use it in GitHub Desktop.
iOS UIFont Sensible Defaults
import Foundation
extension UIFont {
class func systemFontOfSize(size: CGFloat) -> UIFont {
return UIFont(name: "HelveticaNeue", size: size)!
}
class func italicSystemFontOfSize(size: CGFloat) -> UIFont {
return UIFont(name: "HelveticaNeue-Italic", size: size)!
}
class func boldSystemFontOfSize(size: CGFloat) -> UIFont {
return UIFont(name: "HelveticaNeue-Bold", size: size)!
}
class func mediumSystemFontOfSize(size: CGFloat) -> UIFont {
return UIFont(name: "HelveticaNeue-Medium", size: size)!
}
class func lightSystemFontOfSize(size: CGFloat) -> UIFont {
return UIFont(name: "HelveticaNeue-Light", size: size)!
}
class func thinSystemFontOfSize(size: CGFloat) -> UIFont {
return UIFont(name: "HelveticaNeue-Thin", size: size)!
}
class func ultraLightSystemFontOfSize(size: CGFloat) -> UIFont {
return UIFont(name: "HelveticaNeue-UltraLight", size: size)!
}
class func preferredFontForTextStyle(style: NSString) -> UIFont {
switch style {
case UIFontTextStyleBody:
return UIFont.systemFontOfSize(15)
case UIFontTextStyleHeadline:
return UIFont.lightSystemFontOfSize(30)
case UIFontTextStyleSubheadline:
return UIFont.lightSystemFontOfSize(17)
case UIFontTextStyleFootnote:
return UIFont.systemFontOfSize(13)
case UIFontTextStyleCaption1:
return UIFont.systemFontOfSize(12)
case UIFontTextStyleCaption2:
return UIFont.systemFontOfSize(11)
default:
return UIFont.systemFontOfSize(15)
}
}
}
@Querschlag
Copy link

Still in Xcode 7.0 (7A220)...
Did you manage to solve the problem?

@c3farrell
Copy link

maybe add "@nonobjc" above each class func

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment