Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to input an argument into CGContextSetRGBFillColor?

I'm trying to input the arguments for CGContextSetRGBFillColor using a data type. For example:

NSString *colorcode = ctx, 0, 1, 0, 0; 
CGContextSetRGBFillColor(colorcode);

But I get an error saying that I have too few arguments.

I want to change the arguments (ctx, 0, 1, 0, 1 ) sent to CGContextSetRGBFillColor depending on the users actions.

I want to input the argument for CGContextSetRGBFillColor using a data type because the values of it is set in a separate view controller. Or can I directly input the arguments to CGContextSetRGBFillColor and then bring it over to the other view controller to use it?

like image 900
user1053078 Avatar asked Nov 26 '11 06:11

user1053078


2 Answers

Try using a UIColor object to store the user's selected color. You can create one like this:

UIColor *color = [UIColor colorWithRed:0 green:1 blue:0 alpha:0];

Then when it's time to use it as the fill color, you can do this:

CGContextSetFillColorWithColor(ctx, color.CGColor);

I should mention that if you are not using ARC, you need to retain and release color appropriately.

like image 174
rob mayoff Avatar answered Oct 19 '22 23:10

rob mayoff


Sounds like what you really need to be doing is:

CGContextSetRGBFillColor (ctx, 0.0f, 1.0f, 0.0f, 1.0f);

Where each color component is some fraction between 0.0 and 1.0.

Why are you using a NSString?

Here is the documentation on Apple's website.

like image 34
Michael Dautermann Avatar answered Oct 20 '22 01:10

Michael Dautermann