开发者

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

开发者 https://www.devze.com 2023-02-12 06:40 出处:网络
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\"

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

精彩评论

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