I\'m creating a color object using the following code.
curView.backgroundColor = [[UIColor alloc] initWithHue:229 saturation:40 brightness:75 alpha:1];
Just made a category for this.
NSLog(@"%f", [UIColor blueColor].blue); // 1.000000
Goes something like:
typedef enum { R, G, B, A } UIColorComponentIndices;
@implementation UIColor (EPPZKit)
-(CGFloat)red
{ return CGColorGetComponents(self.CGColor)[R]; }
-(CGFloat)green
{ return CGColorGetComponents(self.CGColor)[G]; }
-(CGFloat)blue
{ return CGColorGetComponents(self.CGColor)[B]; }
-(CGFloat)alpha
{ return CGColorGetComponents(self.CGColor)[A]; }
@end
Part of eppz!kit with more UIColor goodies.
UIColor *color = [[UIColor greenColor] retain]; //line 1
//OR(You will have color variable either like line 1 or line 2)
color = curView.backgroundColor;//line 2
CGColorRef colorRef = [color CGColor];
int _countComponents = CGColorGetNumberOfComponents(colorRef);
if (_countComponents == 4) {
const CGFloat *_components = CGColorGetComponents(colorRef);
CGFloat red = _components[0];
CGFloat green = _components[1];
CGFloat blue = _components[2];
CGFloat alpha = _components[3];
NSLog(@"%f,%f,%f,%f",red,green,blue,alpha);
}
[color release];
set your UIColor like this
UIColor.FromRGB(128, 179, 255)
this is for Xamarin ios... but for sure there is a method like this in swift.