Hex color value in objective-c

I have a hex value in mind that I need to implement while working on the ipad. Anyway, how can I implement this with objective-c

Help what you need, prayers and thanks!

+6
objective-c ipad
source share
1 answer

The UIColor range is from 0 to 1. Therefore, you just need to convert the hexadecimal color string to decimal, and then divide by 255 to get the numbers you need.

For example, if the color is #E0EAF1 :

  • Convert hexadecimal to decimal: E0 → 224, EA → 234, F1 → 241
  • Divide by 255: 224 → 0.878, 234 → 0.918, 241 → 0.945

So, to create this color, use

 UIColor* clr = [UIColor colorWithRed:0.878f green:0.918f blue:0.945f alpha:1]; 

or let the compiler do the calculation for you:

 UIColor* clr = [UIColor colorWithRed:0xE0/255.0f green:0xEA/255.0f blue:0xF1/255.0f alpha:1]; 
+22
source share

All Articles