xcode iPhone,需要深蓝色作为 UIColor(用于表格详细信息文本)#336699
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3943607/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iPhone, need the dark blue color as a UIColor (used on tables details text) #336699
提问by Jules
I'm trying to assign blue text like this, exactly like this
我正在尝试像这样分配蓝色文本,就像这样
I'm using my own text field.
我正在使用我自己的文本字段。
In hex the color is #336699
在十六进制中,颜色是 #336699
I need to access my text color to this, I would have liked to use a UIColor but there doesn't seem to be one.
我需要访问我的文本颜色,我本来希望使用 UIColor 但似乎没有。
回答by Stelian Iancu
UIColor
needs it's values in RGB/255.0f. You can find herea converter. In your case, your color is R:51, G:102, B:153.
UIColor
需要 RGB/255.0f 中的值。你可以在这里找到一个转换器。在您的情况下,您的颜色是 R:51、G:102、B:153。
So the code to get your UIColor
is then:
因此,获取您的代码UIColor
是:
UIColor *myColor = [UIColor colorWithRed:51.0f/255.0f green:102.0f/255.0f blue:153.0f/255.0f alpha:1.0f];
回答by Matthias Bauch
I wrote a category for UIColor to convert hex-style colors to UIColors
我为 UIColor 写了一个类别来将十六进制样式的颜色转换为 UIColors
+ (UIColor *)colorWithHex:(UInt32)col {
unsigned char r, g, b;
b = col & 0xFF;
g = (col >> 8) & 0xFF;
r = (col >> 16) & 0xFF;
return [UIColor colorWithRed:(double)r/255.0f green:(double)g/255.0f blue:(double)b/255.0f alpha:1];
}
UIColor *newColor = [UIColor colorWithHex:0x336699];
回答by mxcl
I found a blog about this, and in there someone had made a comment where they'd written some code to print out the exact values used to the log. This is the exact specification for the Slate Blue color that Apple uses:
我找到了一个关于这个的博客,在那里有人发表了评论,他们写了一些代码来打印出用于日志的确切值。这是 Apple 使用的 Slate Blue 颜色的确切规格:
[UIColor colorWithRed:0.22f green:0.33f blue:0.53f alpha:1.0f]
Here's a category:
这是一个类别:
@interface UIColor (mxcl)
+ (UIColor *)slateBlueColor;
@end
@implementation UIColor (mxcl)
+ (UIColor *)slateBlueColor { return [UIColor colorWithRed:0.22f green:0.33f blue:0.53f alpha:1.0f]; }
@end
回答by Neeraj Neeru
better use the bicolor converter
最好使用双色转换器
http://www.touch-code-magazine.com/web-color-to-uicolor-convertor/
http://www.touch-code-magazine.com/web-color-to-uicolor-convertor/