Swift converting on Swift a color RGBa to object UIColor
Notice: A non well formed numeric value encountered in /home/batteur/www/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118
Notice: A non well formed numeric value encountered in /home/batteur/www/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119
Here is a small function that lets you convert a hexadecimal color code with or without alpha layer. They allow me to convert of object UIColor from color style of a KML file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
func UIColorFromRGBA(rgbaValue: String, alpha: Float = 1.0) -> UIColor { var scanner = NSScanner(string: rgbaValue) var color: UInt32 = 0; scanner.scanHexInt(&color) var cAlpha = alpha if count(rgbaValue) > 6 { cAlpha = Float((color>>24) & 0xFF) / 255.0 } return UIColor( red: CGFloat(color & 0xFF) / 255.0, green: CGFloat((color>>8) & 0xFF) / 255.0, blue: CGFloat((color>>16) & 0xFF) / 255.0, alpha: CGFloat(cAlpha) ) } |