how to get Hex code from RGB value using objective c
Could any one help me how to convert the RGB value to Hex co开发者_JS百科de through iphone application? Thanks in advance.
Following @Олег Трахман's answer...
UIColor* myColor = [UIColor brownColor];
const CGFloat* components;
components = CGColorGetComponents(myColor.CGColor);
NSLog(@"%f, %f, %f, %f", components[0],components[1],components[2],components[3]);
NSLog(@"%X, %X, %X, %X", (char)(255*components[0]), (char)(255*components[1]), (char)(255*components[2]), (char)(255*components[3]));
int hexValue = 0xFF0000*components[0] + 0xFF00*components[1] + 0xFF*components[2]; // for RGB
Should output:
0.600000, 0.400000, 0.200000, 1.000000
99, 66, 33, FF
And give you the actual Hex.
UIColor* myColor = [UIColor brownColor];
CGFloat* components;
components = CGColorGetComponents(myColor.CGColor);
NSLog(@"%f, %f, %f, %f", components[0],components[1],components[2],components[3]);
=> 0.600000, 0.400000, 0.200000, 1.000000
精彩评论