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];
kennytm
source share