Skip to content

Instantly share code, notes, and snippets.

@sajadabedi
Forked from jimmyhillis/UIFont+CustomFont.swift
Last active September 6, 2022 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sajadabedi/c5cd4221f74cc7412fdfed8d2d4d9a43 to your computer and use it in GitHub Desktop.
Save sajadabedi/c5cd4221f74cc7412fdfed8d2d4d9a43 to your computer and use it in GitHub Desktop.
Custom font 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