class func hex(hexString: String) -> UIColor { var cString: String = hexString.trimmingCharacters(in: .whitespacesAndNewlines) if cString.count < 6 { return UIColor.black }
let index = cString.index(cString.endIndex, offsetBy: -6) let subString = cString[index...]
if cString.hasPrefix("0X") { cString = String(subString) } if cString.hasPrefix("#") { cString = String(subString) }
if cString.count != 6 { return UIColor.black }
var range = NSRange(location: 0, length: 2) let rString = (cString as NSString).substring(with: range) range.location = 2 let gString = (cString as NSString).substring(with: range) range.location = 4 let bString = (cString as NSString).substring(with: range)
var r: UInt32 = 0x0 var g: UInt32 = 0x0 var b: UInt32 = 0x0