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
let shadowColor = UIColor(red: 204.0/255.0, green: 204.0/255.0, blue: 204.0/255.0, alpha: 1.0) | |
let shadowColorWithAlpha = UIColor(red: 204.0/255.0, green: 204.0/255.0, blue: 204.0/255.0, alpha: 0.5) | |
let customColorWithAlpha = UIColor(red: 18.0/255.0, green: 62.0/255.0, blue: 221.0/255.0, alpha: 0.25) |
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
let shadowColor = Color.shadow.value | |
let shadowColorWithAlpha = Color.shadow.withAlpha(0.5) | |
let customColorWithAlpha = Color.custom(hexString: "#123edd", alpha: 0.25).value |
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 Foundation | |
import UIKit | |
// Usage Examples | |
let shadowColor = Color.shadow.value | |
let shadowColorWithAlpha = Color.shadow.withAlpha(0.5) | |
let customColorWithAlpha = Color.custom(hexString: "#123edd", alpha: 0.25).value | |
enum Color { | |
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
class Utility { | |
/// Logs all available fonts from iOS SDK and installed custom font | |
class func logAllAvailableFonts() { | |
for family in UIFont.familyNames { | |
print("\(family)") | |
for name in UIFont.fontNames(forFamilyName: family) { | |
print(" \(name)") | |
} | |
} |
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
enum FontName: String { | |
case RobotoBlack = "Roboto-Black" | |
case RobotoBlackItalic = "Roboto-BlackItalic" | |
case RobotoBold = "Roboto-Bold" | |
case RobotoBoldItalic = "Roboto-BoldItalic" | |
case RobotoItalic = "Roboto-Italic" | |
case RobotoLight = "Roboto_Light" | |
case RobotoLightItalic = "Roboto-LightItalic" | |
case RobotoMedium = "Roboto-Medium" | |
case RobotoMediumItalic = "Roboto-MediumItalic" |
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
enum FontType { | |
case installed(FontName) | |
case custom(String) | |
case system | |
case systemBold | |
case systemItatic | |
case systemWeighted(weight: Double) | |
case monoSpacedDigit(size: Double, weight: Double) | |
} | |
enum FontSize { |
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
struct Font { | |
enum FontType { | |
case installed(FontName) | |
// ... | |
} | |
enum FontSize { | |
case standard(StandardSize) | |
// ... | |
} | |
enum FontName: String { |
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
extension Font { | |
var instance: UIFont { | |
var instanceFont: UIFont! | |
switch type { | |
case .custom(let fontName): | |
guard let font = UIFont(name: fontName, size: CGFloat(size.value)) else { | |
fatalError("\(fontName) font is not installed, make sure it is added in Info.plist and logged with Utility.logAllAvailableFonts()") | |
} | |
instanceFont = font | |
case .installed(let fontName): |
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
let system12 = UIFont.systemFont(ofSize: 12.0) // Hard coded literals -> 1 | |
let robotoThin20 = UIFont(name: "Roboto-Thin", size: 20.0) // Hard coded literals -> 2 | |
let robotoBlack14 = UIFont(name: "Roboto-Black", size: 14.0) // Hard coded literals -> 2 | |
let helveticaLight13 = UIFont(name: "Helvetica-Light", size: 13.0) // Hard coded literals -> 2 |
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
let system12 = Font(.system, size: .standard(.h5)).instance | |
let robotoThin20 = Font(.installed(.RobotoThin), size: .standard(.h1)).instance | |
let robotoBlack14 = Font(.installed(.RobotoBlack), size: .standard(.h4)).instance | |
let helveticaLight13 = Font(.custom("Helvetica-Light"), size: .custom(13.0)).instance |