Setting CGFillColor from UIColor

Discussion in 'iOS Programming' started by Duke Leto, Jan 25, 2009.

  1. Duke Leto macrumors regular

    Joined:
    Mar 17, 2008
    #1
    I have a UIColor, and I want to use it for the CGContextSetFillColor() method. I tried
    PHP:
    CGColorRef fillColor = [theColor CGColor];
    CGContextRef context UIGraphicsGetCurrentContext();
    CGContextSetFillColor(contextfillColor);
    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?
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Try using CGContextSetFillColorWithColor instead.
     
  3. Duke Leto thread starter macrumors regular

    Joined:
    Mar 17, 2008
    #3
    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.
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    How is theColor defined?
     
  5. Duke Leto thread starter macrumors regular

    Joined:
    Mar 17, 2008
  6. Duke Leto thread starter macrumors regular

    Joined:
    Mar 17, 2008
    #6
    Is there any way to create a custom color that can become a CGColorRef?
     
  7. phjo macrumors regular

    Joined:
    Jan 8, 2008
    #7
    why not do [theColor setFill]; instead ?

    phjo
     
  8. Duke Leto thread starter macrumors regular

    Joined:
    Mar 17, 2008

Share This Page