1

I found this code while trying to customize the color of my table cell in iOS

UIColor *textlabelColor = [[UIColor alloc] initWithRed:1.0f green:0.5f blue:0.5f alpha:1.0f];

The issue is how does this translate to hex color codes. I generally use this page for converting color codes to Hex

http://www.w3schools.com/html/html_colorvalues.asp

How do I translate the hex codes to the UIColor definition?

4 Answers4

1

If you click any of the specific link of the color like this http://www.w3schools.com/tags/ref_color_tryit.asp?hex=FFFFFF. In this link RGBs of these colors are mentioned which you can mention in your initWithRed method.

For example one color code is FF1493 and its RGB is mentioned in this link as 255,20,147 so your initWithRed method would be link this. [[UIColor alloc] initWithRed:255.0f green:20.0f blue:147.0f alpha:1.0f];

0
#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]

Use digital meter to get the HEXValue and pass the rgbValue like (0xFFFFFF)

Rajesh
  • 10,318
  • 16
  • 44
  • 64
0

Infact I found the simplest solution to this one, using this website

http://scratch.johnnypez.com/hex-to-uicolor/

0

step1: Go to www.colorpicker.com to get hex color code

step2: Go to this link: http://www.touch-code-magazine.com/web-color-to-uicolor-convertor to get exact objective c code.

Hope this helps.

gunas
  • 1,889
  • 1
  • 16
  • 29