Last active
January 16, 2019 06:06
-
-
Save imkevinxu/b92fa70f37e4846bcd27 to your computer and use it in GitHub Desktop.
iOS UIFont Sensible Defaults
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
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) | |
} | |
} | |
} |
Still in Xcode 7.0 (7A220)...
Did you manage to solve the problem?
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
This code should be very useful, but i get a lot of errors. I'm using XCode 7.