Skip to content

Instantly share code, notes, and snippets.

@iandundas
Last active August 2, 2021 22:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iandundas/ee0f3a7ecaffa1acf847e7758f0b3f43 to your computer and use it in GitHub Desktop.
Save iandundas/ee0f3a7ecaffa1acf847e7758f0b3f43 to your computer and use it in GitHub Desktop.
Example of creating an App Theme using structs
public protocol ThemeScheme{
var fonts: FontScheme {get}
var colours: ColourScheme {get}
}
public struct Theme: ThemeScheme{
public let fonts: FontScheme
public let colours: ColourScheme
public init(fonts: FontScheme = Fonts(), colours: ColourScheme = Colours()){
self.fonts = fonts
self.colours = colours
}
}
public protocol ColourScheme{
var primaryColor: UIColor {get} // default colour in scheme
var textOnPrimaryColour: UIColor {get}
var secondaryColor: UIColor {get} // ie. selected colour of controls
var black: UIColor {get}
var white: UIColor {get}
var lightGrey: UIColor {get}
var darkGrey: UIColor {get}
}
public struct Colours: ColourScheme{
public let primaryColor = UIColor(red:0.17, green:0.49, blue:0.85, alpha:1.00)
public let textOnPrimaryColour = UIColor(red:0.85, green:0.92, blue:0.89, alpha:1.00)
public let secondaryColor = UIColor(red:0.99, green:0.19, blue:0.35, alpha:1.00)
public let black = UIColor(red:0.08, green:0.06, blue:0.13, alpha:1.00)
public let white = UIColor(red:0.97, green:0.97, blue:0.97, alpha:1.00)
public let lightGrey = UIColor(red:0.84, green:0.84, blue:0.84, alpha:1.00)
public let darkGrey = UIColor(red:0.56, green:0.56, blue:0.58, alpha:1.00)
}
public protocol FontScheme{
var navigationTitle: UIFont {get}
var cellHeaderText: UIFont {get}
var cellImageCaptionText: UIFont {get}
var cellImageSmallCaptionText: UIFont {get}
var headerText: UIFont {get}
var bodyText: UIFont {get}
var captionText: UIFont {get}
var textField: UIFont {get}
var searchBar: UIFont {get}
var button: UIFont {get}
}
public struct Fonts: FontScheme {
public let navigationTitle = UIFont(name: "AvenirNextCondensed-DemiBold", size: 25)!
public let cellHeaderText = UIFont(name: "Avenir-Book", size: 29)!
public let cellImageCaptionText = UIFont(name: "Avenir-Light", size: 17)!
public let cellImageSmallCaptionText = UIFont(name: "Avenir-Heavy", size: 17)!
public let headerText = UIFont(name: "AvenirNext-Medium", size: 15)!
public let bodyText = UIFont(name: "Avenir-Light", size: 15)!
public let captionText = UIFont(name: "Avenir-Light", size: 15)!
public let hyperlinkText = UIFont(name: "Avenir-Medium", size: 15)!
public let textField = UIFont(name: "Avenir-Book", size: 27)!
public let searchBar = UIFont(name: "Avenir-Light", size: 17)!
public let button = UIFont(name: "AvenirNext-Regular", size: 17)!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment