Is there a faster (or better) way to get color components [RGBA] from UIColor? It seems that there are many variations of this (some here, in fact, are similar to what I did here). I am just wondering if there is an alternative, as this seems a bit "missing", given that everything else is usually so complete and thought out.
if([eachKey isEqualToString:@"NSColor"]) { UIColor *newColor = [attrs valueForKey:eachKey]; //NSLog(@"COLOR: %@", newColor); CGColorRef colorRef = [newColor CGColor]; //NSLog(@"%@", colorRef); int numComponets = CGColorGetNumberOfComponents(colorRef); if(numComponets == 4) { const CGFloat *components = CGColorGetComponents(colorRef); CGFloat compR = components[0]; CGFloat compG = components[1]; CGFloat compB = components[2]; CGFloat compA = components[3]; //NSLog(@"R:%f G:%f B:%f, A:%f", compR, compG, compB, compA); } }
I'm not looking for how (I think I have a long version above). I just would like to know if this is how you expected to do it now?
source share