Alessandro
Alessandro

Reputation: 4100

CGContextSetRGBFillColor too few arguments

I am trying to set a color to my CGContextSetRGBFillColor in this way:

- (void) drawArrowWithContext:(CGContextRef)context atPoint:(CGPoint)startPoint withSize: (CGSize)size lineWidth:(float)width arrowHeight:(float)aheight andColor:(UIColor *)color
{   
CGContextSetRGBFillColor (context,color,color,color,1);
CGContextSetRGBStrokeColor (context, color.CGColor);

....
}

...but I am getting in both cases the error "Too few arguments, should be 5, are 2". How can I fix this issue?

Upvotes: 0

Views: 914

Answers (2)

Stavash
Stavash

Reputation: 14304

From the documentation:

void CGContextSetRGBFillColor (
   CGContextRef c,
   CGFloat red,
   CGFloat green,
   CGFloat blue,
   CGFloat alpha
);

All you need to do is break apart your UIColor using

- (BOOL)getRed:(CGFloat *)red green:(CGFloat *)green blue:(CGFloat *)blue alpha:(CGFloat *)alpha

Upvotes: 1

spring
spring

Reputation: 18487

Seeing your other question, I would suggest that you stop for an hour and do some reading of the docs rather than simply trying to hammer your way through without understanding or learning anything.

You have a problem in your code: you are passing in a UIColor and trying to use it in a function which takes floats as arguments. Either change the params for you method or use a different CoreGraphics function which can accept a UIColor (or rather the CGColor represenation of that).

CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextSetStrokeColorWithColor(context,[color CGColor]);

Upvotes: 7

Related Questions