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
Custom UI Control
Second, quartz2d in the IOS value in development
in order to facilitate the construction of beautiful UI interface, IOS provides a UIKit Frame,?? There are a variety of UI Controls
UILabel : Explicit text
Uiimageview : Show Pictures
UIButton : Display both picture and Word (can click)
Lee? UIKit the framework provides controls that are pieced together to build and present some simple, common UI sector?
However, some UI the interface is extremely complex, and is more personal, common UI control cannot be implemented, you can use quartz2d technology draws the structure inside the control and customizes the control's appearance
in fact, IOS The contents of some controls are quartz2d it's drawn.
therefore, quartz2d in the IOS What is important in development? A value is: Custom View (custom UI controls)
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 PDF ? documents, Bitmap or on the display window)
The same set of drawing sequences that specify different Graphics Context , you can draw the same image to a different target
Iv. Custom View
How to use quartz2d ? Define View ? (? definition UI control)
How to use quartz2d Draw Something to View up?
First, you have to have a graphical context, because it saves the drawing information and determines where to draw it.
Next, the graph up and down? View To draw the content to the View above
? 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
V. 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 was the law called?
when View The first time it is displayed on the screen (it is added to the uiwindow )
called View of the Setneedsdisplay or Setneedsdisplayinrect: when
2.quartz2d Notice
quartz2d of the API is pure C Language of speech
quartz2d of the API from the Core Graphics Frame
the data types and functions are basically CG as a prefix
Cgcontextref
Cgpathref
Cgcontextstrokepath (CTX);
3.drawRect: in the context of the
in the DrawRect: method, you can draw something into the View on
View inside there is a Layer (Layer) property, DrawRect: The method is obtained by a Layer Graphics Context and so, the drawing of something is actually drawn to the View of the Layer go up.
View The only thing that can be displayed is because of its internal Layer