Created
August 28, 2020 18:30
-
-
Save olgusirman/18ccaa35c6ea0d8a2ca2d0cde0ec8bf0 to your computer and use it in GitHub Desktop.
Protocol Oriented approach for font usage
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
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