Forked from jimmyhillis/UIFont+CustomFont.swift
Last active
September 6, 2022 19:39
-
-
Save sajadabedi/c5cd4221f74cc7412fdfed8d2d4d9a43 to your computer and use it in GitHub Desktop.
Custom font Swift
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 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