Skip to content

Instantly share code, notes, and snippets.

@olgusirman
Created August 28, 2020 18:30
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 olgusirman/18ccaa35c6ea0d8a2ca2d0cde0ec8bf0 to your computer and use it in GitHub Desktop.
Save olgusirman/18ccaa35c6ea0d8a2ca2d0cde0ec8bf0 to your computer and use it in GitHub Desktop.
Protocol Oriented approach for font usage
protocol CustomFontsProtocol {
func size(size: CGFloat) -> UIFont?
}
extension CustomFontsProtocol where Self: RawRepresentable, Self.RawValue == String {
func size(size: CGFloat) -> UIFont? {
return UIFont(name: rawValue, size: size)
}
}
enum SourceSansPro : String, CustomFontsProtocol {
case semiBold = "SourceSansPro-SemiBold"
}
let s = SourceSansPro.semiBold.size(size: 18)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment