4
votes

I have an image in Fireworks. I am using the picker to choose the color and then look at the RGB values. I am putting these values into UIColor:colorWithRed:green:blue:alpha but it is not giving me the same output. I am using values between 1.0 and 0.0.

I am trying to get a dark blue color, the UIColor is giving me a very light blue.

Ideas?

4
What values are you passing to the class method? - gerry3
copy&paste the UIColor instanciating and (if needed) instanciating of the RGB-values used. Also copy&paste the line where you assign that UIColor to an element. My bet is that you have a type-conversion mixup in your code. Ow, and please copy&paste the exact values that fireworks is showing you for that color. - Till

4 Answers

10
votes

Sounds to me like your calculations for converting the value from fireworks to the value necessary in UIColor is off.

example:

Fireworks RGB values red:64 green:87 blue:188

divide those three number each by 255

gives you [UIColor colorWithRed:0.250980392156863 green:0.341176470588235 blue:0.462745098039216 alpha:1.0]

7
votes

Add this to a header file: (something like helpers.h)

#define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]

Then add this to the YourApp_Prefix.pch file

#import "helpers.h"

Finally whenever you need a color you would use this:

UIColor* myColor = RGBCOLOR(64,87,188);
0
votes

Ensure that you are retrieving float values by including decimal points in your statement.

UIColor *myColor = [UIColor colorWithRed:16.0/255 green:176.0/255 blue:230.0/255 alpha:1]; 

Hope that helps.

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

define kbackGroundColor UIColorFromRGB(0x00A99D)

use this code with best of RGB on hex Coloring....Cheers