I’ve been using a hex calculator to convert hex values to RGB values ( #666 = 102/102/102 and so on).
It seems I can’t use this with UIColor though, [UIColor colorWithRed:102 green:102 blue:102 alpha: 1.0] just seems to return white (tried 60 too). If I use [UIColor colorWithWhite: 0.6 alpha:1.0] I get a dark color- so how can I convert a value like 102/102/102 into a colorWithWhite value?
A way I’ve tried is to take that value and divide by 255, so 102/255 = 0.4 so I set my colorWithWhite value to 0.4. Is that accurate?
+ (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alphaParameters:
red – The red component of the color object, specified as a value from 0.0 to 1.0.
green – The green component of the color object, specified as a value from 0.0 to 1.0.
blue – The blue component of the color object, specified as a value from 0.0 to 1.0.
alpha – The opacity value of the color object, specified as a value from 0.0 to 1.0.
So to convert your RGB values to be between 0.0 and 1.0, do #/255
Edit: In response to your edit, yes it’s correct. But remember if you do that in code, you’re doing integer division and you’ll get 0. Make the 255 a float variable or use the constant 255.f