I use enums for this
enum AppColor: UInt32 {
case DarkBlue = 0x00437C
case LightBlue = 0x7CCEF0
var color: UIColor {
return UIColor(hex: rawValue)
}
}
This way it is easy to reuse same color in xib
/storyboard
because I have hex values ready for copy/paste. And also less code needed for defining new color
For creating colors from hex value I used UIColor
extension:
extension UIColor {
public convenience init(hex: UInt32) {
let mask = 0x000000FF
let r = Int(hex >> 16) & mask
let g = Int(hex >> 8) & mask
let b = Int(hex) & mask
let red = CGFloat(r) / 255
let green = CGFloat(g) / 255
let blue = CGFloat(b) / 255
self.init(red:red, green:green, blue:blue, alpha:1)
}
}