-2

I am trying to create the below color in Xcode, but cannot seem to get it to match?

enter image description here

I have tried the following:

setBackgroundColor:[[UIColor alloc] initWithRed:0 green:47 blue:135 alpha:1]];

Is there something I am doing wrong, or should change the color does not match what I expect?

StuartM
  • 6,743
  • 18
  • 84
  • 160
  • 1
    Reminder - as you type in a question, SO shows you related questions that may already answer your question. A quick look at those related questions would have shown you the answer. – rmaddy Mar 28 '13 at 00:22

2 Answers2

3

Try this

setBackgroundColor:[[UIColor alloc] initWithRed:15/255.0f green:47/255.0f blue:135/255.f alpha:1]];

UIColor expects the colors to be a value between 0 and 1, so you have to divide those values by 255.

Ares
  • 5,905
  • 3
  • 35
  • 51
0

If you want to use as RGB value then you can define it as like below:

#define RGB(r,g,b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]
andykkt
  • 1,696
  • 16
  • 23
  • You really should put parentheses in there: `#define RGB(r,g,b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]`. Without those parentheses, you will have issues with code like: `UIColor *c = RGB(x + 4, y - 10, z - t);`. – rmaddy Mar 28 '13 at 01:15
  • Yes, you are right.. I was in a hurry..;) – andykkt Mar 28 '13 at 01:25