开发者

What is the easiest way to get a hex color code from a set of color percentages in Objective-c?

What is the best way to get a hex color code from a set of three RGB percentages? For example:

[self getHexFromRed:0.5 Green:0.5 Blue:0.5]; // returns @"7F7F7F"

I've found several functions for going the other way (creating a color from a hex code), but I c开发者_运维百科an't seem to find any easy way to do this...

Thanks for any help,

Chris


You could write it from scratch:

[NSString stringWithFormat:@"%02X%02X%02X", 255 * redAsFloat,
                                            255 * greenAsFloat,
                                            255 * blueAsFloat];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜