Amogh Talpallikar
Amogh Talpallikar

Reputation: 12184

How to draw two CGMutablePaths with different colors?

I wanted to draw different set of lines in the same loop inside drawRect but with different color. say set of lines with blue and the other with red alternatively.

initially, I was using two different for loops and and stroking the context twice with different colors.

But then I came across CGMutablePathRef and decided to use two different paths and stroke them with different colors and write code in the same for loop.

Now my problem is that I couldn't find way to set a color for a path. It appears that we can only set color for Context and not to paths.

I am quite new to iOS and cocoa.

What should I do ? Shall I add the first path to context, set the color, stroke the path and then add the other stroke to the context and set the new color and stroke the context again.

Is there a better,neater and cleaner way for doing this ?

Upvotes: 0

Views: 597

Answers (1)

Kurt Revis
Kurt Revis

Reputation: 27994

Shall I add the first path to context, set the color, stroke the path and then add the other stroke to the context and set the new color and stroke the context again.

Yes, that's how you do it.

Upvotes: 1

Related Questions