Kodeco Forums

Video Tutorial: Beginning Core Graphics Part 3: Contexts 1

In this core graphics video tutorial series you'll learn about drawing contexts and saving context state.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3402-beginning-core-graphics/lessons/4

hey, thanks. this is a very good series so far. I have a question though. When you are adding a clipping path to a context, how does the context know whether all drawing from then on will be inside or outside that path? For example, if you have a square rect of 200 x 200, and you add a clipping path down the center (vertically), will all drawing from then on occur on the right or left side of that line?

If we add an arc path as a clipping path, does all drawing from now on occur inside the path? that is what i think would happen, but what if we instead want all drawing to occur outside?

thanks

If you do path.addClip() it means that all drawing outside that path is excluded.

If you have a straight line, i.e. not a closed shape, I’m not sure what it does. It didn’t seem to draw anything when I tried. But I wouldn’t do that anyway as it doesn’t make sense.

So create a closed path. Adding a clip means that drawing is done inside that path.

Is it necessary to begin and end the context in the class funcs in DrawIcon? Those funcs are returning a UIBezierPath so I don’t understand the need to use contexts. Thanks!

1 Like

That’s a really good catch - of course there’s no need for a context because no actual drawing is taking place.

Thanks for pointing that out!