[Swift]16進数文字列からrgb取得

16進数文字列からrgb取得

class func getColorTupleByColorHex(colorHex:String) -> (r:CGFloat,g:CGFloat,b:CGFloat){
    let colorScanner:NSScanner = NSScanner(string: colorHex)
    var color:UInt32 = 0
    colorScanner.scanHexInt(&color)
    let r:CGFloat = CGFloat((color & 0xFF0000) >> 16) / CGFloat(255.0);
    let g:CGFloat = CGFloat((color & 0x00FF00) >> 8)  / CGFloat(255.0);
    let b:CGFloat = CGFloat(color & 0x0000FF) / CGFloat(255.0);
    return (r: r, g: g, b: b)
}