Skip to content

Instantly share code, notes, and snippets.

@jimmyhillis
Created December 15, 2014 13:28
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jimmyhillis/dfb8711dc696246f817e to your computer and use it in GitHub Desktop.
Save jimmyhillis/dfb8711dc696246f817e to your computer and use it in GitHub Desktop.
UIFont+CustomFont.swift
import UIKit
extension UIFont {
class func systemFontOfSize(size: CGFloat) -> UIFont {
return UIFont(name: "CustomFont-Regular", size: size)!
}
func lightSystemFontOfSize(size: CGFloat) -> UIFont {
return UIFont(name: "CustomFont-Light", size: size)!
}
func boldSystemFontOfSize(size: CGFloat) -> UIFont {
return UIFont(name: "CustomFont-Bold", size: size)!
}
func preferredFontForTextStyle(style: String) -> UIFont {
switch(style) {
case UIFontTextStyleBody:
return UIFont.systemFontOfSize(17)
case UIFontTextStyleHeadline:
return UIFont.boldSystemFontOfSize(17)
case UIFontTextStyleSubheadline:
return UIFont.systemFontOfSize(15)
case UIFontTextStyleFootnote:
return UIFont.systemFontOfSize(13)
case UIFontTextStyleCaption1:
return UIFont.systemFontOfSize(12)
case UIFontTextStyleCaption2:
return UIFont.systemFontOfSize(11)
default:
return UIFont.systemFontOfSize(17)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment