Created
February 23, 2015 22:42
Revisions
-
chrishulbert created this gist
Feb 23, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ import UIKit extension UIColor { /// Creates a UIColor from an 'rrggbb' hex string. class func fromHex(hexColour: String) -> UIColor { let str = hexColour.cStringUsingEncoding(NSUTF8StringEncoding) let x = strtol(str!, nil, 16) let r = x >> 16 let g = (x >> 8) & 0xff let b = x & 0xff let red = CGFloat(r) / 255.0 let green = CGFloat(g) / 255.0 let blue = CGFloat(b) / 255.0 return UIColor(red: red, green: green, blue: blue, alpha: 1) } }