Quartz2d Drawing Detailed

Source: Internet
Author: User

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) 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

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.