3

I have created a UIColor object and want to set the colors before drawing using CGContextSetRGBStrokeColor. In order to do that I need to extract the values of red, green and blue from the UIColor object. How do I do that?

Or is there perhaps a better way defining the color using some other kind of methods (couldn't find when I looked for it though) in which I can use the UIColor object to set the color?

Thanks in advance!

/Niklas

Nicsoft
  • 3,644
  • 9
  • 41
  • 70

2 Answers2

11

You don't need the RGB components in your case. Just use CGContextSetStrokeColorWithColor instead of CGContextSetRGBStrokeColor.

CGContextSetStrokeColorWithColor(context, thatUIColor.CGColor);

(To get the RGB components, see How to get RGB values from UIColor?.)

Community
  • 1
  • 1
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
0

If you made a color on a desktop, just look up the RGB values in the color picker. Here: http://sketchup.google.com/support/bin/answer.py?hl=en&answer=96105

Otherwise, you could just use the "default" colors, if you don'T care much about the RGB values of a color.

Like this:

[UIColor redColor]

Look at the documentation for more info.

tadejsv
  • 2,085
  • 1
  • 18
  • 20
  • I didn't really need to know the actual value, but it is important that it is exactly the same color that is used as the UIColor represents. I don't really know how to apply the [UIColor redColor] since it only returns a new UIColor, don't think that helps me. And the hole point is not to specify the RGB-values by hand but to reuse what is already represented by another UIColor object. Thanks anyway! – Nicsoft Jul 18 '10 at 17:35