1

Is it possible to give custom color codes to UIKit controls?

Either by passing hex color values or working with RGB values?

Just noticed in the documentation there is a initWithRed:green:blue:alpha: method

Any way of getting hex codes to work?

MrShoot
  • 843
  • 1
  • 9
  • 21
  • 1
    duplicate of [this](http://stackoverflow.com/questions/3805177/how-to-convert-hex-rgb-color-codes-to-uicolor) and [this](http://stackoverflow.com/questions/1560081/iphone-change-hex-color-format-to-uicolor) and [this](http://stackoverflow.com/questions/3010216/how-can-i-convert-rgb-hex-string-into-uicolor-in-objective-c) question already answered on SO. – progrmr Aug 12 '11 at 03:22
  • Great! Thanks for links. And sorry for the double post, I couldn't find the other ones – MrShoot Aug 14 '11 at 20:59

2 Answers2

6

A use of the following macro would allow me to accomplish what I am looking for

#define UIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

To change the color is just a matter of calling the macro

self.view.backgroundColor = UIColorFromRGB(0xFEBFBF);
MrShoot
  • 843
  • 1
  • 9
  • 21
2

Your other option is to convert your hex values to RGB and enter them in the interface builder.

enter image description here

Kyle Clegg
  • 38,547
  • 26
  • 130
  • 141