iOS Development UI Chapter-quartz2d Brief Introduction
First, what is quartz2d
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
Customizing UI Controls
Second, the value of quartz2d in the development of iOS
iOS provides a uikit framework for easy-to-build UI interface,?? There are a variety of UI controls
UILabel: Explicit text
Uiimageview: Show Pictures
UIButton: Simultaneous display of pictures and words (can click)
Philip? Uikit Framework provides controls that can be pieced together to build and realistically some simple, common UI realms?
However, some UI interfaces are extremely complex, and more personalized, and the normal UI controls cannot be implemented, so you can use the quartz2d technique to draw the structure inside the control and customize what the control looks like
In fact, the contents of some controls in iOS are drawn through quartz2d.
So, quartz2d is important in iOS development. The value is: Custom view (custom UI control)
Three, the 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)
The same set of drawing sequences, specifying different graphics Context, can draw the same image to different targets
Iv. 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) Implementation-(void) DrawRect: (cgrect) rect. 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
V. Additional Information
1.drawRect:
(1) Why do you want to achieve drawrect:? Law to draw to view?
Because the graphical context associated with the view can be obtained in the DrawRect:? method
(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);
3.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
iOS Development UI Chapter-quartz2d Brief Introduction