Quartz 2D is a two-dimensional drawing engine that supports both iOS and Mac systems
Quartz 2D can do the job:
Drawing: lines \ triangles \ rectangles \ Circles \ Arcs, etc.
Draw text
Draw \ Generate picture (image)
Read \ Generate PDF
\ crop a picture
Custom UI Control
in fact,IOSThe contents of some controls arequartz2dit's drawn.
therefore,quartz2din theIOSWhat is important in development? A value is: CustomView(CustomUIcontrol)
Graphics context
Graphics context: is a cgcontextref type of data
The role of the graphics context:
(1) Save drawing information, drawing status
(2) Decide which output target to draw (to what place?) (The output target can be a PDF file, a bitmap or a display window)
Custom View
How do I use quartz2d? To define a view? (? Define UI controls)
How to use quartz2d to draw things to the view?
First, you have to have a graphical context, because it saves the drawing information and determines where to draw it.
Second, the graph up and down? must be associated with view to draw content to view
? To define a view:
(1) Create a new class, Inherit from UIView
(2) Realize -(void) DrawRect: ( CGRect ) Rectmethod. And then in this? Method:
1) Obtain A graphical context associated with the current view;
2) draw the corresponding graphic content
3) render all rendered content to the view using the graphical context
Additional Information
1.drawRect:
(1) Why do you want to achieve drawrect:? Law to draw to view?
because in DrawRect: in order to obtain View The associated graphics context
(2) DrawRect: When is the law called?
When view is first displayed on the screen (added to UIWindow)
Call view's Setneedsdisplay or Setneedsdisplayinrect: when
2.QUARTZ2D Notice
Quartz2d's API is pure C language.
Quartz2d's API comes from the core graphics framework
Data types and functions are basically prefixed with CG
Cgcontextref
Cgpathref
Cgcontextstrokepath (CTX);
DrawRect: The top and bottom of the text
After you get the context in the DrawRect: method, you can draw something to the view
There is a layer property inside the view, DrawRect: A layer Graphics Context is obtained in the method, so the drawing is actually drawn to the view layer.
View is able to show things entirely because of its inner layer
Quartz2d Drawing Detailed