Skip to content

Instantly share code, notes, and snippets.

@mohsinbmwm3
Created January 18, 2021 14:35
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 mohsinbmwm3/f6fb4cd82e7ad33cf65a0dc2f24a309f to your computer and use it in GitHub Desktop.
Save mohsinbmwm3/f6fb4cd82e7ad33cf65a0dc2f24a309f to your computer and use it in GitHub Desktop.
Some custom font swift extension ideas.
import UIKit
// Its better to create custom font name as constant to avoid spelling mistakes when using this.
extension String {
static let appCustomFontRegular = "Montserrat"
static let appCustomFontBold = "Montserrat-Bold"
}
extension UIFont {
static func appRegularFont(size: CGFloat) -> UIFont {
return UIFont(name: String.appCustomFontRegular, size: size) ?? .systemFont(ofSize: size)
}
static func appBoldFont(size: CGFloat) -> UIFont {
return UIFont(name: String.appCustomFontBold, size: size) ?? .boldSystemFont(ofSize: size)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment