Chris
Chris

Reputation: 127

UIColor not matching RGB

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?

Upvotes: 4

Views: 4319

Answers (4)

Ghanshyam Tomar
Ghanshyam Tomar

Reputation: 770

#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

Upvotes: 0

Craig Gilchrist
Craig Gilchrist

Reputation: 71

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);

Upvotes: 7

Yup.
Yup.

Reputation: 1893

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.

Upvotes: 0

scottbates22
scottbates22

Reputation: 326

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]

Upvotes: 10

Related Questions