I'm trying to assign blue text like this, exactly like this
I'm using my own text field.
In hex开发者_C百科 the color is #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
needs it's values in RGB/255.0f. You can find here a converter. In your case, your color is R:51, G:102, B:153.
So the code to get your UIColor
is then:
UIColor *myColor = [UIColor colorWithRed:51.0f/255.0f green:102.0f/255.0f blue:153.0f/255.0f alpha:1.0f];
I wrote a category for UIColor to convert hex-style colors to 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];
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:
[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
better use the bicolor converter
http://www.touch-code-magazine.com/web-color-to-uicolor-convertor/
精彩评论