Skip to content

Instantly share code, notes, and snippets.

@iosdevben
Created November 22, 2019 19:40
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 iosdevben/f79af5abfd88f554133882a6af794b2f to your computer and use it in GitHub Desktop.
Save iosdevben/f79af5abfd88f554133882a6af794b2f to your computer and use it in GitHub Desktop.
//
// UIColor+Carsales.swift
// CSAppKit
//
// Created by Ben Thomas on 22/11/19.
// Copyright © 2019 Carsales.com.au. All rights reserved.
//
import Foundation
@objc public class CSColourObjc: NSObject {
@objc public class func uiColor(from csColour: CSColour) -> UIColor {
return csColour.uiColor
}
}
@objc public enum CSColour: Int {
// MARK: Backgrounds
case darkViewBackground // always dark
case viewBackground
case secondaryViewBackground
// MARK: Cards, lists, forms
case listItemBackground
case listContainerBackground
// MARK: Labels, Text Views, etc
case text
case secondaryText
case tertiaryText
// MARK: Borders and Separators/Keylines
case border
case separator
// MARK: Buttons, icons, etc
case standardCallToAction
case prominentCallToAction
// MARK: Other controls
case activePageControl
case inactivePageControl
// MARK: Other
case facebookBlue
case googleRed
// MARK: -
public var uiColor: UIColor {
switch self {
case .border: return .border
case .separator: return .separatorLine
case .darkViewBackground: return .darkViewBackground
case .viewBackground: return .viewBackground
case .secondaryViewBackground: return .secondaryViewBackground
case .standardCallToAction: return .standardCallToAction
case .prominentCallToAction: return .prominentCallToAction
case .listItemBackground: return .listItemBackground
case .listContainerBackground: return .listContainerBackground
case .text: return .text
case .secondaryText: return .secondaryText
case .tertiaryText: return .tertiaryText
case .facebookBlue: return .facebookBlue
case .googleRed: return .googleRed
case .activePageControl: return .inactivePageControl
case .inactivePageControl: return .inactivePageControl
}
}
}
// MARK: -
private extension UIColor {
// MARK: - Fundamental
static var primaryBackground: UIColor {
if #available(iOS 13.0, *) {
return .systemBackground
} else {
return .white
}
}
static var secondaryBackground: UIColor {
if #available(iOS 13.0, *) {
return .secondarySystemBackground
} else {
return UIColor.RGB(242, 242, 242) // was cs_bgGrey
}
}
// MARK: - Backgrounds
static var viewBackground: UIColor {
if #available(iOS 13.0, *) {
return .systemBackground
} else {
return .white
}
}
static var secondaryViewBackground: UIColor {
if #available(iOS 13.0, *) {
return .secondarySystemBackground
} else {
return UIColor.RGB(242, 242, 242)
}
}
static var darkViewBackground: UIColor {
return UIColor.RGB(51, 51, 51)
}
// MARK: - Cards, lists and forms
static var listItemBackground: UIColor { return .primaryBackground }
static var listContainerBackground: UIColor { return .secondaryBackground }
// MARK: Labels, Text Views, etc
static var text: UIColor {
if #available(iOS 13.0, *) {
return .label
} else {
return UIColor.RGB(51, 51, 51) // was csdarkergrey51s
}
}
static var secondaryText: UIColor {
if #available(iOS 13.0, *) {
return .secondaryLabel
} else {
return UIColor.RGB(135, 135, 135) // was csdarkergrey135s
}
}
static var tertiaryText: UIColor {
if #available(iOS 13.0, *) {
return .tertiaryLabel
} else {
return UIColor.RGB(203, 203, 203) // was csdarkergrey203s
}
}
// MARK: - Borders and Keylines
static var border: UIColor {
if #available(iOS 13.0, *) {
return .separator
} else {
return UIColor.RGB(214, 214, 214)
}
}
static var separatorLine: UIColor {
if #available(iOS 13.0, *) {
return .separator
} else {
return UIColor.RGB(221, 221, 221)
}
}
// MARK: - Buttons, icons, etc
static var standardCallToAction: UIColor {
return UIColor(named: "standardCallToAction") ?? UIColor.RGB(28, 136, 201) // was cs_carsBlue()
}
static var prominentCallToAction: UIColor {
return UIColor(named: "prominentCallToAction") ?? UIColor.RGB(255, 137, 65) // was cs_orange()
}
// MARK: - Other Controls
static var activePageControl: UIColor {
return UIColor.text
}
static var inactivePageControl: UIColor {
return UIColor.secondaryText
}
// MARK: - Other
static var facebookBlue: UIColor {
return UIColor(named: "facebookBlue") ?? UIColor.RGB(59, 89, 152) // was cs_facebookBlue
}
static var googleRed: UIColor {
return UIColor(named: "googleRed") ?? UIColor.RGB(211, 72, 54) // was cs_googleRed
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment