views:

1083

answers:

3

Hello,

How can I set UIcolor to have a deepblue values (like 330099, shown in interface builder) programmatically?

Thanks.

+2  A: 

Just use Jeff LaMarche's UIColor extensions....

http://iphonedevelopment.blogspot.com/2008/11/more-colors-more-compact.html

and here:

http://iphonedevelopment.blogspot.com/2008/10/little-color-in-your-life.html

You can see how it is done.

Corey Floyd
+5  A: 

To create a UIColor based on RGB values you need to do:

[UIColor colorWithRed:0x33/255.0 green:0 blue:0x99/255.0 alpha:1.0]
pgb
Thanks, it worked
ebaccount
+1  A: 

Or in stead of using 0x33 / 255.0 use the actual float for the color value, this of course requires you to convert the values.

[UIColor colorWithRed:51.0 / 255.0, green:0.0, blue:153.0 / 255.0];

As long as you use a floating point value in your division you don't have to cast anything. Make sure you use floating point values. For example: 33 / 255 = 0. Which will become black.

klaaspieter
Your example is confusing... 0x33 is 51 in Hex, not 33, that's why he should use 0x33.
pgb
You are right, I've adapted the example to use the correct values. I just wanted to point out that you don't have to use the hexadecimal values.
klaaspieter