Skip to content

Instantly share code, notes, and snippets.

@kishorek
Forked from jimmyhillis/UIFont+CustomFont.swift
Created November 9, 2017 06:13
Show Gist options
  • Save kishorek/a901cf0edcdd14da288bdf8a05875086 to your computer and use it in GitHub Desktop.
Save kishorek/a901cf0edcdd14da288bdf8a05875086 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: UIFontTextStyle) -> UIFont {
switch(style) {
case UIFontTextStyle.body:
return UIFont.systemFont(ofSize: 17)
case UIFontTextStyle.headline:
return UIFont.boldSystemFont(ofSize: 17)
case UIFontTextStyle.subheadline:
return UIFont.systemFont(ofSize: 15)
case UIFontTextStyle.footnote:
return UIFont.systemFont(ofSize: 13)
case UIFontTextStyle.caption1:
return UIFont.systemFont(ofSize: 12)
case UIFontTextStyle.caption2:
return UIFont.systemFont(ofSize: 11)
default:
return UIFont.systemFont(ofSize: 17)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment