PDA

View Full Version : Setting CGFillColor from UIColor




Duke Leto
Jan 25, 2009, 10:13 AM
I have a UIColor, and I want to use it for the CGContextSetFillColor() method. I tried

CGColorRef fillColor = [theColor CGColor];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColor(context, fillColor);


The problem is a warning saying
"passing argument 2 of 'CGContextSetFillColor' from incompatible pointer type"

How can I use the UIColor to set my fill color?



dejo
Jan 25, 2009, 01:07 PM
Try using CGContextSetFillColorWithColor instead.

Duke Leto
Jan 25, 2009, 01:20 PM
Now I don't have any warnings, but when I try to set a CGColorRef to [theColor CGColor], the application crashes.
:confused:

Another thing I found: this only happens when I make the color with [UIColor colorWithRed:Blue:Green:Alpha];, but if I use [UIColor cyanColor] or something, it works.

dejo
Jan 25, 2009, 01:26 PM
Now I don't have any warnings, but when I try to set a CGColorRef to [theColor CGColor], the application crashes.
:confused:
How is theColor defined?

Duke Leto
Jan 25, 2009, 01:37 PM
With [UIColor colorWithRed:blue:green];

Duke Leto
Jan 25, 2009, 02:06 PM
Is there any way to create a custom color that can become a CGColorRef?

phjo
Jan 25, 2009, 02:37 PM
why not do [theColor setFill]; instead ?

phjo

Duke Leto
Jan 25, 2009, 03:15 PM
Wow, I can't believe I didn't think of that!
:)