Skip to content

Instantly share code, notes, and snippets.

@ethanmick
Created January 28, 2017 17:27
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 ethanmick/bc98cb704b6f39e5ee5ac3b437f85538 to your computer and use it in GitHub Desktop.
Save ethanmick/bc98cb704b6f39e5ee5ac3b437f85538 to your computer and use it in GitHub Desktop.
A quick way to get all of Material Design's colors into your Swift app. These can be combined into a single file if you want.
import Foundation
import UIKit
struct MDColor {
static let red = redColorPallete()
static let pink = pinkColorPallete()
static let purple = purpleColorPallete()
static let deepPurple = deepPurpleColorPallete()
static let indigo = indigoColorPallete()
static let blue = blueColorPallete()
static let lightBlue = lightBlueColorPallete()
static let cyan = cyanColorPallete()
static let teal = tealColorPallete()
static let green = greenColorPallete()
static let lightGreen = lightGreenColorPallete()
static let lime = limeColorPallete()
static let yellow = yellowColorPallete()
static let amber = amberColorPallete()
static let orange = orangeColorPallete()
static let deepOrange = deepOrangeColorPallete()
static let brown = brownColorPallete()
static let grey = greyColorPallete()
static let blueGrey = blueGreyColorPallete()
}
struct redColorPallete {
let md50 = UIColor.hex("#ffebee")
let md100 = UIColor.hex("#ffcdd2")
let md200 = UIColor.hex("#ef9a9a")
let md300 = UIColor.hex("#e57373")
let md400 = UIColor.hex("#ef5350")
let md500 = UIColor.hex("#f44336")
let md600 = UIColor.hex("#e53935")
let md700 = UIColor.hex("#d32f2f")
let md800 = UIColor.hex("#c62828")
let md900 = UIColor.hex("#b71c1c")
let mdA100 = UIColor.hex("#ff8a80")
let mdA200 = UIColor.hex("#ff5252")
let mdA400 = UIColor.hex("#ff1744")
let mdA700 = UIColor.hex("#d50000")
}
struct pinkColorPallete {
let md50 = UIColor.hex("#fce4ec")
let md100 = UIColor.hex("#f8bbd0")
let md200 = UIColor.hex("#f48fb1")
let md300 = UIColor.hex("#f06292")
let md400 = UIColor.hex("#ec407a")
let md500 = UIColor.hex("#e91e63")
let md600 = UIColor.hex("#d81b60")
let md700 = UIColor.hex("#c2185b")
let md800 = UIColor.hex("#ad1457")
let md900 = UIColor.hex("#880e4f")
let mdA100 = UIColor.hex("#ff80ab")
let mdA200 = UIColor.hex("#ff4081")
let mdA400 = UIColor.hex("#f50057")
let mdA700 = UIColor.hex("#c51162")
}
struct purpleColorPallete {
let md50 = UIColor.hex("#f3e5f5")
let md100 = UIColor.hex("#e1bee7")
let md200 = UIColor.hex("#ce93d8")
let md300 = UIColor.hex("#ba68c8")
let md400 = UIColor.hex("#ab47bc")
let md500 = UIColor.hex("#9c27b0")
let md600 = UIColor.hex("#8e24aa")
let md700 = UIColor.hex("#7b1fa2")
let md800 = UIColor.hex("#6a1b9a")
let md900 = UIColor.hex("#4a148c")
let mdA100 = UIColor.hex("#ea80fc")
let mdA200 = UIColor.hex("#e040fb")
let mdA400 = UIColor.hex("#d500f9")
let mdA700 = UIColor.hex("#aa00ff")
}
struct deepPurpleColorPallete {
let md50 = UIColor.hex("#ede7f6")
let md100 = UIColor.hex("#d1c4e9")
let md200 = UIColor.hex("#b39ddb")
let md300 = UIColor.hex("#9575cd")
let md400 = UIColor.hex("#7e57c2")
let md500 = UIColor.hex("#673ab7")
let md600 = UIColor.hex("#5e35b1")
let md700 = UIColor.hex("#512da8")
let md800 = UIColor.hex("#4527a0")
let md900 = UIColor.hex("#311b92")
let mdA100 = UIColor.hex("#b388ff")
let mdA200 = UIColor.hex("#7c4dff")
let mdA400 = UIColor.hex("#651fff")
let mdA700 = UIColor.hex("#6200ea")
}
struct indigoColorPallete {
let md50 = UIColor.hex("#e8eaf6")
let md100 = UIColor.hex("#c5cae9")
let md200 = UIColor.hex("#9fa8da")
let md300 = UIColor.hex("#7986cb")
let md400 = UIColor.hex("#5c6bc0")
let md500 = UIColor.hex("#3f51b5")
let md600 = UIColor.hex("#3949ab")
let md700 = UIColor.hex("#303f9f")
let md800 = UIColor.hex("#283593")
let md900 = UIColor.hex("#1a237e")
let mdA100 = UIColor.hex("#8c9eff")
let mdA200 = UIColor.hex("#536dfe")
let mdA400 = UIColor.hex("#3d5afe")
let mdA700 = UIColor.hex("#304ffe")
}
struct blueColorPallete {
let md50 = UIColor.hex("#e3f2fd")
let md100 = UIColor.hex("#bbdefb")
let md200 = UIColor.hex("#90caf9")
let md300 = UIColor.hex("#64b5f6")
let md400 = UIColor.hex("#42a5f5")
let md500 = UIColor.hex("#2196f3")
let md600 = UIColor.hex("#1e88e5")
let md700 = UIColor.hex("#1976d2")
let md800 = UIColor.hex("#1565c0")
let md900 = UIColor.hex("#0d47a1")
let mdA100 = UIColor.hex("#82b1ff")
let mdA200 = UIColor.hex("#448aff")
let mdA400 = UIColor.hex("#2979ff")
let mdA700 = UIColor.hex("#2962ff")
}
struct lightBlueColorPallete {
let md50 = UIColor.hex("#e1f5fe")
let md100 = UIColor.hex("#b3e5fc")
let md200 = UIColor.hex("#81d4fa")
let md300 = UIColor.hex("#4fc3f7")
let md400 = UIColor.hex("#29b6f6")
let md500 = UIColor.hex("#03a9f4")
let md600 = UIColor.hex("#039be5")
let md700 = UIColor.hex("#0288d1")
let md800 = UIColor.hex("#0277bd")
let md900 = UIColor.hex("#01579b")
let mdA100 = UIColor.hex("#80d8ff")
let mdA200 = UIColor.hex("#40c4ff")
let mdA400 = UIColor.hex("#00b0ff")
let mdA700 = UIColor.hex("#0091ea")
}
struct cyanColorPallete {
let md50 = UIColor.hex("#e0f7fa")
let md100 = UIColor.hex("#b2ebf2")
let md200 = UIColor.hex("#80deea")
let md300 = UIColor.hex("#4dd0e1")
let md400 = UIColor.hex("#26c6da")
let md500 = UIColor.hex("#00bcd4")
let md600 = UIColor.hex("#00acc1")
let md700 = UIColor.hex("#0097a7")
let md800 = UIColor.hex("#00838f")
let md900 = UIColor.hex("#006064")
let mdA100 = UIColor.hex("#84ffff")
let mdA200 = UIColor.hex("#18ffff")
let mdA400 = UIColor.hex("#00e5ff")
let mdA700 = UIColor.hex("#00b8d4")
}
struct tealColorPallete {
let md50 = UIColor.hex("#e0f2f1")
let md100 = UIColor.hex("#b2dfdb")
let md200 = UIColor.hex("#80cbc4")
let md300 = UIColor.hex("#4db6ac")
let md400 = UIColor.hex("#26a69a")
let md500 = UIColor.hex("#009688")
let md600 = UIColor.hex("#00897b")
let md700 = UIColor.hex("#00796b")
let md800 = UIColor.hex("#00695c")
let md900 = UIColor.hex("#004d40")
let mdA100 = UIColor.hex("#a7ffeb")
let mdA200 = UIColor.hex("#64ffda")
let mdA400 = UIColor.hex("#1de9b6")
let mdA700 = UIColor.hex("#00bfa5")
}
struct greenColorPallete {
let md50 = UIColor.hex("#e8f5e9")
let md100 = UIColor.hex("#c8e6c9")
let md200 = UIColor.hex("#a5d6a7")
let md300 = UIColor.hex("#81c784")
let md400 = UIColor.hex("#66bb6a")
let md500 = UIColor.hex("#4caf50")
let md600 = UIColor.hex("#43a047")
let md700 = UIColor.hex("#388e3c")
let md800 = UIColor.hex("#2e7d32")
let md900 = UIColor.hex("#1b5e20")
let mdA100 = UIColor.hex("#b9f6ca")
let mdA200 = UIColor.hex("#69f0ae")
let mdA400 = UIColor.hex("#00e676")
let mdA700 = UIColor.hex("#00c85")
}
struct lightGreenColorPallete {
let md50 = UIColor.hex("#f1f8e9")
let md100 = UIColor.hex("#dcedc8")
let md200 = UIColor.hex("#c5e1a5")
let md300 = UIColor.hex("#aed581")
let md400 = UIColor.hex("#9ccc65")
let md500 = UIColor.hex("#8bc34a")
let md600 = UIColor.hex("#7cb342")
let md700 = UIColor.hex("#689f38")
let md800 = UIColor.hex("#558b2f")
let md900 = UIColor.hex("#33691e")
let mdA100 = UIColor.hex("#ccff90")
let mdA200 = UIColor.hex("#b2ff59")
let mdA400 = UIColor.hex("#76ff03")
let mdA700 = UIColor.hex("#64dd17")
}
struct limeColorPallete {
let md50 = UIColor.hex("#f9fbe7")
let md100 = UIColor.hex("#f0f4c3")
let md200 = UIColor.hex("#e6ee9c")
let md300 = UIColor.hex("#dce775")
let md400 = UIColor.hex("#d4e157")
let md500 = UIColor.hex("#cddc39")
let md600 = UIColor.hex("#c0ca33")
let md700 = UIColor.hex("#afb42b")
let md800 = UIColor.hex("#9e9d24")
let md900 = UIColor.hex("#827717")
let mdA100 = UIColor.hex("#f4ff81")
let mdA200 = UIColor.hex("#eeff41")
let mdA400 = UIColor.hex("#c6ff00")
let mdA700 = UIColor.hex("#aeea0")
}
struct yellowColorPallete {
let md50 = UIColor.hex("#fffde7")
let md100 = UIColor.hex("#fff9c4")
let md200 = UIColor.hex("#fff59d")
let md300 = UIColor.hex("#fff176")
let md400 = UIColor.hex("#ffee58")
let md500 = UIColor.hex("#ffeb3b")
let md600 = UIColor.hex("#fdd835")
let md700 = UIColor.hex("#fbc02d")
let md800 = UIColor.hex("#f9a825")
let md900 = UIColor.hex("#f57f17")
let mdA100 = UIColor.hex("#ffff8d")
let mdA200 = UIColor.hex("#ffff00")
let mdA400 = UIColor.hex("#ffea00")
let mdA700 = UIColor.hex("#ffd600")
}
struct amberColorPallete {
let md50 = UIColor.hex("#fff8e1")
let md100 = UIColor.hex("#ffecb3")
let md200 = UIColor.hex("#ffe082")
let md300 = UIColor.hex("#ffd54f")
let md400 = UIColor.hex("#ffca28")
let md500 = UIColor.hex("#ffc107")
let md600 = UIColor.hex("#ffb300")
let md700 = UIColor.hex("#ffa000")
let md800 = UIColor.hex("#ff8f00")
let md900 = UIColor.hex("#ff6f00")
let mdA100 = UIColor.hex("#ffe57f")
let mdA200 = UIColor.hex("#ffd740")
let mdA400 = UIColor.hex("#ffc400")
let mdA700 = UIColor.hex("#ffab00")
}
struct orangeColorPallete {
let md50 = UIColor.hex("#fff3e0")
let md100 = UIColor.hex("#ffe0b2")
let md200 = UIColor.hex("#ffcc80")
let md300 = UIColor.hex("#ffb74d")
let md400 = UIColor.hex("#ffa726")
let md500 = UIColor.hex("#ff9800")
let md600 = UIColor.hex("#fb8c00")
let md700 = UIColor.hex("#f57c00")
let md800 = UIColor.hex("#ef6c00")
let md900 = UIColor.hex("#e65100")
let mdA100 = UIColor.hex("#ffd180")
let mdA200 = UIColor.hex("#ffab40")
let mdA400 = UIColor.hex("#ff9100")
let mdA700 = UIColor.hex("#ff6d00")
}
struct deepOrangeColorPallete {
let md50 = UIColor.hex("#fbe9e7")
let md100 = UIColor.hex("#ffccbc")
let md200 = UIColor.hex("#ffab91")
let md300 = UIColor.hex("#ff8a65")
let md400 = UIColor.hex("#ff7043")
let md500 = UIColor.hex("#ff5722")
let md600 = UIColor.hex("#f4511e")
let md700 = UIColor.hex("#e64a19")
let md800 = UIColor.hex("#d84315")
let md900 = UIColor.hex("#bf360c")
let mdA100 = UIColor.hex("#ff9e80")
let mdA200 = UIColor.hex("#ff6e40")
let mdA400 = UIColor.hex("#ff3d00")
let mdA700 = UIColor.hex("#dd2c00")
}
struct brownColorPallete {
let md50 = UIColor.hex("#efebe9")
let md100 = UIColor.hex("#d7ccc8")
let md200 = UIColor.hex("#bcaaa4")
let md300 = UIColor.hex("#a1887f")
let md400 = UIColor.hex("#8d6e63")
let md500 = UIColor.hex("#795548")
let md600 = UIColor.hex("#6d4c41")
let md700 = UIColor.hex("#5d4037")
let md800 = UIColor.hex("#4e342e")
let md900 = UIColor.hex("#3e2723")
}
struct greyColorPallete {
let md50 = UIColor.hex("#fafafa")
let md100 = UIColor.hex("#f5f5f5")
let md200 = UIColor.hex("#eeeeee")
let md300 = UIColor.hex("#e0e0e0")
let md400 = UIColor.hex("#bdbdbd")
let md500 = UIColor.hex("#9e9e9e")
let md600 = UIColor.hex("#757575")
let md700 = UIColor.hex("#616161")
let md800 = UIColor.hex("#424242")
let md900 = UIColor.hex("#212121")
}
struct blueGreyColorPallete {
let md50 = UIColor.hex("#eceff1")
let md100 = UIColor.hex("#cfd8dc")
let md200 = UIColor.hex("#b0bec5")
let md300 = UIColor.hex("#90a4ae")
let md400 = UIColor.hex("#78909c")
let md500 = UIColor.hex("#607d8b")
let md600 = UIColor.hex("#546e7a")
let md700 = UIColor.hex("#455a64")
let md800 = UIColor.hex("#37474f")
let md900 = UIColor.hex("#263238")
}
import Foundation
import UIKit
extension UIColor {
static func hex(_ hex: String) -> UIColor {
var cString:String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
if (cString.hasPrefix("#")) {
cString.remove(at: cString.startIndex)
}
if ((cString.characters.count) != 6) {
return UIColor.gray
}
var rgbValue:UInt32 = 0
Scanner(string: cString).scanHexInt32(&rgbValue)
return UIColor(
red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
alpha: CGFloat(1.0)
)
}
}
@ethanmick
Copy link
Author

The MDColor file was autogenerated, don't worry. I didn't write it by hand 🙃

Usage:

let color = MDColor.grey.md500

Let me know if you have any comments!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment