Comparison of Cgpath Cgcontext Uibezierpath

Source: Internet
Author: User
PATHVIEW.M//Qauze////Created by Apple on 16/6/2. copyright©2016 the year of Li Chongyang.
All rights reserved. #import "PathView.h" @implementation Pathview-(Instancetype) initWithFrame: (CGRect) Frame {if (self = [super] in
    Itwithframe:frame]) {self.backgroundcolor = [uicolor Bluecolor];
} return self;

    }-(void) DrawRect: (cgrect) rect {[Self cgpath];

    [Self cgcontext];

    [Self Bézier];
[Self drawround];
    }/* * One: Cgpath **/-(void) Cgpath {cgcontextref ref = Uigraphicsgetcurrentcontext ();
    Cgmutablepathref pathref = cgpathcreatemutable ();
    1. Set the starting point Cgpathmovetopoint (Pathref, Nil, 5, 5);
    2. Join line Cgpathaddlinetopoint (Pathref, Nil, 50, 50);
    3. Place path into Contextref Cgcontextaddpath (ref, PATHREF);

    Cgpathrelease (PATHREF);


[[Uicolor Redcolor]setstroke]; Cgcontextsetstrokecolorwithcolor (ref, [Uicolor Redcolor].
    Cgcolor); /* * This sentence must be added or not to start drawing * This is the beginning of drawing Cgpath path **/CgcontexTstrokepath (ref);
    }/* II: Draw directly with Cgcontext **/-(void) Cgcontext {cgcontextref ref = Uigraphicsgetcurrentcontext ();
    Cgcontextmovetopoint (ref, 50, 50);
    Cgcontextaddlinetopoint (ref, 100, 100);
    Cgcontextaddlinetopoint (ref, 10, 60);
    Cgcontextsetlinewidth (ref, 5);
    Cgcontextsetlinecap (ref, Kcglinecapround);

    Cgcontextsetlinejoin (ref, Kcglinejoinbevel);
    [[Uicolor Yellowcolor]setfill];


    [[Uicolor Cyancolor]setstroke]; /* * 3 ways to draw path * 1.CGCONTEXTFILLPATH (ref); Draw Fill * 2.CGContextStrokePath (ref); Draw strokes * 3.CGContextDrawPath (ref, Kcgpathfillstroke);


Draw fill and Stroke **/cgcontextdrawpath (ref, Kcgpathfillstroke);
    }/* Bézier curve **/-(void) Bézier {uibezierpath * path = [Uibezierpath Bezierpath];
    [Path Movetopoint:cgpointmake (100,100)];
    [Path Addlinetopoint:cgpointmake (200, 100)];
    [Path Addlinetopoint:cgpointmake (150, 200)];
    [Path Setlinecapstyle:kcglinecapround]; [Path Setlinejoinstyle:kcglinejoinbeVEL];
    [Path Setlinewidth:5];
    [[Uicolor Redcolor]setfill];
    [[Uicolor Yellowcolor]setstroke];
    [Path stroke];
    [Path fill];

[Path Closepath];
    }/* Bezier curve Draw circle, ellipse, Sector **/-(void) Drawround {//Draw circle Uibezierpath * Path = [Uibezierpath Bezierpath];
    [Path Addarcwithcenter:cgpointmake (radius:50) startangle:0 endangle:m_pi*1.5 Clockwise:yes];
    [Path setlinewidth:10];
    [[Uicolor Yellowcolor]setstroke];


    [Path stroke];
    Draw Ellipse Uibezierpath * path1 = [Uibezierpath bezierpathwithovalinrect:cgrectmake (0, 0, 100, 200)];
    [Path1 Setlinewidth:5];



[path1 stroke];




















 } @end

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.