Quartz2D introduction, quartz2d

Source: Internet
Author: User

Quartz2D introduction, quartz2d

1. What is Quartz2D?

Quartz 2D is a two-dimensional Drawing Engine that supports both iOS and Mac systems.

Jobs that can be completed by Quartz 2D:

Drawing: lines, triangles, rectangles, circles, and Arcs

Draw text

Draw \ generate image (image)

Read \ generate PDF

\ Crop an image

Custom UI controls

Ii. Quartz2D's value in iOS development

In order to build a beautiful UI interface, iOS provides the UIKit framework, which has various UI controls.

UILabel: explicit text

UIImageView: displays images

UIButton: displays the image and text simultaneously (can be clicked)

Leveraging the components provided by the UIKit framework, you can combine them to build a simple and common UI environment.

However, some UI interfaces are extremely complex, customized, and customized, so the ordinary UI controls of the Custom cannot be implemented. In this case, you can use Quartz2D technology to draw the internal structure of the control and customize the display of the control.

In fact, the content of some controls in iOS is drawn through Quartz2D.

Therefore, the important feature of Quartz2D in iOS development is: Custom view (custom UI control)

Iii. Graphic Context

Graphics Context: A CGContextRef type data.

Role of the graphic context:

(1) Save drawing information and drawing status

(2) determine the output target to be drawn (where is the plot going ?) (The output target can be a PDF swap file, Bitmap, or display window)

The same sequence of drawing sets and different Graphics Context can be specified to draw the same image to different targets.

 

Iv. Custom view

How can I define a view using Quartz2D notebook? (Define the UI control)

How to Use Quartz2D to draw things to the view?

First, there must be a graphical context, because it can save the drawing information and decide where to draw

Second, the image's upper and lower dimensions must be associated with the view to draw the content to the view.

To define a view, follow these steps:

(1) create multiple classes and inherit from UIView.

(2) Implement-(void) drawRect :( CGRect) rect evaluate method. Then in this merge method:

1) obtain the graphic context associated with the current view;

2) Draw the corresponding image content

3) use the graphic context to render all the drawn content to the view.

5. Additional instructions

1. drawRect:

(1) Why do we need to implement the drawRect: drawing method before drawing to the view?

This is because the graphic context associated with the view can be obtained in the drawRect: view method.

(2) When will the drawRect method be called?

When the view is displayed on the screen for the first time (added to UIWindow)

When you call setNeedsDisplay or setNeedsDisplayInRect of view:

 

2. Quartz2D notice

Quartz2D APIs are pure C-speaking APIs.

The Quartz2D API comes from the Core Graphics framework.

Both data types and functions are prefixed with CG.

CGContextRef

CGPathRef

CGContextStrokePath (ctx );

 

3. drawRect: the upper and lower vertices obtained in

After obtaining the context in the drawRect: method, you can draw things to the view.

The View has a layer attribute. drawRect: The method obtains a Layer Graphics Context. Therefore, what you draw is actually drawn to the view layer.

The reason why a View can display things is entirely because of its internal layer

Related Article

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.