Last active
July 23, 2018 13:54
-
-
Save Viveron/b170ec26f647274e7e33233ff5ea9b50 to your computer and use it in GitHub Desktop.
Application's fonts protocol for easy and convenient fonts makeup use
This file contains hidden or 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 Foundation | |
| enum Roboto: String, FontFamily { | |
| case thin = "Roboto-Thin" | |
| case bold = "Roboto-Bold" | |
| case light = "Roboto-Light" | |
| case medium = "Roboto-Medium" | |
| case regular = "Roboto-Regular" | |
| } |
This file contains hidden or 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 Foundation | |
| // MARK: - Application's fonts protocol | |
| protocol FontFamily { | |
| var fontName: String { get } | |
| } | |
| // MARK: - FontFamily Protocol default implementation | |
| extension FontFamily where Self: RawRepresentable, Self.RawValue == String { | |
| var fontName: String { | |
| return rawValue | |
| } | |
| } | |
| // MARK: - UIFont extension for application's UI fonts | |
| extension UIFont { | |
| // Common font sizes in application | |
| enum Size: CGFloat { | |
| case small = 10 | |
| case lite = 12 | |
| case medium = 14 | |
| case normal = 16 | |
| case big = 20 | |
| case extra = 24 | |
| } | |
| convenience init?(_ fontFamily: FontFamily, size: UIFont.Size) { | |
| self.init(name: fontFamily.fontName, size: size.rawValue) | |
| } | |
| convenience init?(_ fontFamily: FontFamily, size: CGFloat) { | |
| self.init(name: fontFamily.fontName, size: size) | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: