tags:

views:

34

answers:

2

I'm trying to assign blue text like this, exactly like this

alt text

I'm using my own text field.

In hex 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.

+1  A: 

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];
Stelian Iancu
+1  A: 

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];
fluchtpunkt
Good one, thanks for posting! Added it to my collection of categories :-).
Stelian Iancu
BTW, I don't know if you know about the cocoa-helpers project on github (here: http://github.com/enormego/cocoa-helpers). It would be cool if you would submit your UIColor category to them to be included in the project.
Stelian Iancu