-
-
Save ibrennan/c873442f410105de1b57 to your computer and use it in GitHub Desktop.
Revisions
-
ibrennan revised this gist
Dec 2, 2014 . 1 changed file with 21 additions and 23 deletions.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 @@ -1,23 +1,21 @@ func hexStringToUIColor (hex:String) -> UIColor { var cString:String = hex.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet() as NSCharacterSet).uppercaseString if (cString.hasPrefix("#")) { cString = cString.substringFromIndex(advance(cString.startIndex, 1)) } if (countElements(cString) != 6) { return UIColor.grayColor() } var rgbValue:UInt32 = 0 NSScanner(string: cString).scanHexInt(&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) ) } -
ibrennan renamed this gist
Dec 2, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
shadcn revised this gist
Jul 26, 2014 . 1 changed file with 4 additions and 4 deletions.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 @@ -10,14 +10,14 @@ func colorWithHexString (hex:String) -> UIColor { return UIColor.grayColor() } var rString = cString.substringToIndex(2) var gString = cString.substringFromIndex(2).substringToIndex(2) var bString = cString.substringFromIndex(4).substringToIndex(2) var r:CUnsignedInt = 0, g:CUnsignedInt = 0, b:CUnsignedInt = 0; NSScanner.scannerWithString(rString).scanHexInt(&r) NSScanner.scannerWithString(gString).scanHexInt(&g) NSScanner.scannerWithString(bString).scanHexInt(&b) return UIColor(red: Float(r) / 255.0, green: Float(g) / 255.0, blue: Float(b) / 255.0, alpha: Float(1)) } -
shadcn created this gist
Jun 5, 2014 .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,23 @@ // Creates a UIColor from a Hex string. func colorWithHexString (hex:String) -> UIColor { var cString:String = hex.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()).uppercaseString if (cString.hasPrefix("#")) { cString = cString.substringFromIndex(1) } if (countElements(cString) != 6) { return UIColor.grayColor() } var rString = cString.substringFromIndex(0).substringToIndex(2) var gString = cString.substringFromIndex(2).substringToIndex(4) var bString = cString.substringFromIndex(4).substringToIndex(6) var r:CUnsignedInt = 0, g:CUnsignedInt = 0, b:CUnsignedInt = 0; NSScanner.scannerWithString(rString).scanHexInt(&r) NSScanner.scannerWithString(gString).scanHexInt(&g) NSScanner.scannerWithString(bString).scanHexInt(&b) return UIColor(red: Double(r) / 255.0, green: Double(g) / 255.0, blue: Double(b) / 255.0, alpha: Double(1)) }