Basic introduction of QUART2D

Source: Internet
Author: User

DrawRect: How to make use of the method?
Drawing of common graphs: lines, polygons, circles

Drawing state settings:? text color, line width, etc.

The preservation and restoration of the state of the graph up and down
Graphics up and down, text stacks

What is quartz2d

    • Quartz 2D is that a? Two-dimensional drawing engine, simultaneously? support for iOS and Mac systems

    • Quartz 2D can be done? work

  • ? Drawing: lines \ Three corners \ rectangles \ Circles \ Arcs, etc.

  • ? Draw? text

  • ? Draw \? Generate diagram Slice (image)

  • ? Read \? Generate PDF

  • ? \ crop chart? Slice

  • ? ? Custom UI Control?......

  • quartz2d instances

    Quartz 2D can do a lot of strong, big things, such as

    ? Crop graph?

    The value of quartz2d in iOS development

    To make it easy to build an aesthetically pleasing UI interface, iOS provides a uikit framework with a variety of UI controls? UILabel: Display text
    ? Uiimageview: showing the picture?
    ? UIButton: Simultaneous display of pictures and words (can click)

    ?......

    Lee? Use the controls provided by the Uikit framework to make a patchwork, to build and to be realistic? Some simple, common UI interface

    However, some UI boundaries are extremely complex, and, what are the more personal, more personalized, common UI controls? Can not be achieved, at this time the structure of the control inside the quartz2d technology to draw out,? Custom control of the sample child

    In fact, the contents of most controls in iOS are drawn through quartz2d.
    So, quartz2d is important in iOS development? A value is:? Custom View (? Custom UI Control)

    Graph up and down?

    Graphics context: Yes? A cgcontextref type of data

    How to make a graph up and down?
    ? Save drawing information, drawing status
    ? Decide which output to draw? Where do you draw the target? (output?) can the target be a PDF file, a bitmap or a display window?? On the mouth)

    The same? A set of drawing sequences that specify different graphics Context to draw the same image to a different target

    ? Custom View

    How do I use quartz2d? Custom view? (? Custom UI Control)

    How to use quartz2d to draw things to the view?
    First, you have to have a graph up and down, because it can save the drawing information and decide where to draw it? Secondly, the graphic must be associated with a view in order to draw the content onto the view?

    ? Steps for customizing view
    ? New? A class, Inherit? Self UIView
    ? Implementation-(void) DrawRect: (CGRect) Rect method, and then in this? method to get the graph associated with the current view up and down?
    Draw the appropriate graphic content
    Do you use graphics up and down? To render all the content that is drawn to the view?

    DrawRect:

    Why do you want to implement the DrawRect:? method to draw to the view?
    ? Because in the DrawRect:? method, you can obtain a graph that is associated with a view.

    DrawRect: When was the method transferred?
    ? When the view is displayed on the screen (is added to the UIWindow display)? To use the Setneedsdisplay or Setneedsdisplayinrect of a view:

    QUARTZ2D Notice

    Quartz2d's API is pure C language.
    quartz2d API to? From the core graphics framework

    A C-language drawing frame in iOS (coregraphics.framwork)

    Framework import, after XCODE5, so the framework named after the. Framework does not have to be imported

    are basic data types and functions prefixed with CG? Cgcontextref
    ? Cgpathref
    ? Cgcontextstrokepath (CTX);

    ? ......

    DrawRect: The top and bottom of the text

    After getting up and down in the DrawRect: method, you can draw things to the view
    There is a layer property inside the view, DrawRect:? The method gets a layer

    Graphics Context, so what you draw is actually drawn to the layer of view.

    The reason that view can be shown is because of its inner layer.

    quartz2d code steps for drawing

    1. Get the graph up and down text
    Cgcontextref CTX = Uigraphicsgetcurrentcontext ();

    2. Stitching path (the next polygon code is a line segment)

    Cgcontextmovetopoint (CTX, 10, 10);

    Cgcontextaddlinetopoint (CTX, 100, 100);

    3. Draw the Path
    Cgcontextstrokepath (CTX); Cgcontextfillpath (CTX);

    Common Use stitching path function

    New? A starting point
    void Cgcontextmovetopoint (Cgcontextref C, CGFloat x, cgfloat y)

    Add a new segment to a point
    void Cgcontextaddlinetopoint (Cgcontextref C, CGFloat x, cgfloat y)

    Add? a rectangle
    void Cgcontextaddrect (Cgcontextref C, CGRect rect)

    Add an ellipse
    void Cgcontextaddellipseinrect (Cgcontextref context, CGRect rect)

    Add? an arc
    void Cgcontextaddarc (Cgcontextref C, CGFloat x, CGFloat y,

    CGFloat radius, cgfloat startangle, CGFloat endangle, Intclockwise)

    Used to draw a path function

    Mode parameter determines the pattern to be drawn
    void Cgcontextdrawpath (cgcontextref C, Cgpathdrawingmode mode)

    Draw Empty Heart Path
    void Cgcontextstrokepath (Cgcontextref c)

    Draw a real heart path
    void Cgcontextfillpath (Cgcontextref c)

    Cgcontextdraw, Cgcontextstroke, and Cgcontextfill are all functions that are used to draw a path.

    The operation of the graph up and down

    Copy the current up and down text, save to the top of the stack (the stack is called "Graph up and down stack") void Cgcontextsavegstate (Cgcontextref c)

    Put the top of the stack up and down, replace the current up and down text
    void Cgcontextrestoregstate (Cgcontextref c)

Basic introduction of QUART2D

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.