Get RBGA values of UIColor

I have been using next method to get RGBA values of UIColor :


This has existed since iOS 5, I guess this method was not able to get values correctly for gray color, for example, [UIColor grayColor], So I had to see its return value (Bool) and I had to use another method if failed.
But I found this method worked for gray color in Swift. And I also tried it in Objective-C, then I found it succeeded. Oh it has changed...

    UIColor *color = [UIColor grayColor];
    CGFloat red,green,blue,alpha;
    [color getRed:&red green:&green blue:&blue alpha:&alpha];

    var red:CGFloat = 0, green:CGFloat = 0, blue:CGFloat = 0, alpha:CGFloat = 0
    color.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
Swift needed initialization.

memo : Swift 1.1
Develop | Comments(0) | Trackback(0)