via An Introduction to Quartz 2D – Tuts+ Code Tutorial.
Quartz 2D is Apple’s 2D drawing engine, an important component of the Core Graphics framework. You may often see Quartz 2D referred to as Core Graphics or simply CG.
Quartz 2D uses the “painter’s model”. In the painter’s model, each successive drawing operation applies a layer of “paint” to an output “canvas”, often called a page. Think of this as an artist working on a painting. If the artist were to paint the entire canvas blue and then paint some clouds onto the canvas then the clouds would cover the blue beneath them. Once something is “painted” onto the canvas, it cannot be changed but by adding more paint atop of it.
All drawing in Quartz 2D is done through a graphics context of type
CGContextRef. With a reference to a graphics context, you can use the Quartz 2D functions to draw to the context, perform operations, such as translating the context, and change graphic state parameters, such as line width and fill color. Quartz 2D is a C-based API, as such you will invoke the C functions passing in the context as a parameter.
To draw to the screen on iOS, you must subclass a
UIView and override its
drawRect(_:)method. It is inside this
drawRect(_:) method that you will do any custom drawing. You should never call the
drawRect(_:) method directly in your code. If you need to update the screen with fresh drawing commands, you should call the methods
When using Quartz 2D on iOS, the coordinate (0,0) is at the top left of the screen. The x coordinate increases as you move right and the y coordinate increases as you move down.
Throughout this tutorial, you may wish to consult the Quartz 2D programming guide. The purpose of this tutorial is to get started using Quartz 2D. There is much that will not be covered and to fully appreciate all that Quartz 2D has to offer I suggest you read the programming guide.
With this brief introduction out of the way, let’s get started using Quartz 2D.