IOS: Drawing

Source: Internet
Author: User

1, Uibezierpath (Bezier curve)

1-1), in the rewrite DrawRect: Method used

Use is not difficult, see UIBEZIERPATH.H Basic will use, it is worth noting that the color settings are as follows:

[[Uicolor Redcolor]set];

Here is the code in the learning process

-(void) DrawRect: (cgrect) rect{//Rectangle Uibezierpath *path1 = [Uibezierpath bezierpathwithrect:cgrectmake (20, 20, 50, 50    )];    [[Uicolor Graycolor]set];    [path1 stroke];    Inscribed circle Uibezierpath *path2 = [Uibezierpath bezierpathwithovalinrect:cgrectmake (100, 20, 50, 50)];    [[Uicolor Bluecolor]set];    [Path2 fill];    [path2 stroke];    Cut 4 fillet Uibezierpath *path3 = [Uibezierpath bezierpathwithroundedrect:cgrectmake (x, X, max) cornerradius:15.0];    [[Uicolor Greencolor]set];    [Path3 stroke]; Cut 1-4 fillet (the last parameter cornerradii, as if the size.width has effect?) ) Uibezierpath *path4 = [Uibezierpath bezierpathwithroundedrect:cgrectmake (a) Byroundingcorners:uirectcor Nertopleft |    Uirectcornerbottomright Cornerradii:cgsizemake (15.0, 35.0)];    [[Uicolor Whitecolor]set];    [Path4 stroke]; Arc Uibezierpath *path5 = [Uibezierpath bezierpathwitharccenter:cgpointmake (+) radius:25.0 StartAngle:M_PI endAn    Gle:m_pi/4 Clockwise:yes];    [[Uicolor Yellowcolor]set]; [Path5 stroke];    Draw Straight line Uibezierpath *path6 = [Uibezierpath Bezierpath];    [Path6 setlinewidth:3.0];    [[Uicolor Redcolor]set];    [Path6 movetopoint:cgpointmake (100, 100)];    [Path6 Addlinetopoint:cgpointmake (150, 100)];    [Path6 Addlinetopoint:cgpointmake (150, 150)];    [Path6 addlinetopoint:cgpointmake (100, 150)];    [Path6 addlinetopoint:cgpointmake (100, 100)];    [Path6 Addlinetopoint:cgpointmake (200, 125)];    [Path6 Addlinetopoint:cgpointmake (150, 150)];    [Path6 Closepath];    Path6.usesevenoddfillrule = YES;    [Path6 fill];        [Path6 stroke];    Bezier curve Uibezierpath *path7 = [Uibezierpath Bezierpath];    [Path7 setlinewidth:5.0];    [[Uicolor Orangecolor]set];    [Path7 movetopoint:cgpointmake (200, 100)]; [Path7 Addcurvetopoint:cgpointmake (275), Controlpoint1:cgpointmake (50) Controlpoint2:cgpointmake    ;        [Path7 stroke];    Bezier curve Uibezierpath *path8 = [Uibezierpath Bezierpath];    [Path8 setlinewidth:5.0]; [[Uicolor Purplecolor]set];    [Path8 movetopoint:cgpointmake (200, 150)];    [Path8 Addquadcurvetopoint:cgpointmake, Controlpoint:cgpointmake (250, 200)];        [Path8 stroke];    Arc Uibezierpath *path9 = [Uibezierpath Bezierpath] with center to start angle segment;    [Path9 setlinewidth:5.0];    [[Uicolor Browncolor]set];    [Path9 Movetopoint:cgpointmake (50, 200)];    [Path9 addarcwithcenter:cgpointmake (radius:25.0) startangle:0.0 endangle:m_pi Clockwise:yes];        [Path9 stroke];    Dashed Uibezierpath *path10 = [Uibezierpath Bezierpath];    [Path10 setlinewidth:5.0];    [[Uicolor Whitecolor]set];    [Path10 Movetopoint:cgpointmake (10, 300)];    [Path10 Addlinetopoint:cgpointmake (SCREEN_WIDTH-10, 300)];    CGFloat linedash[] = {10.0,2.0,5.0,5.0};    Odd solid lines, even dashed lines, phase start offset [path10 setlinedash:linedash count:4 phase:0]; [Path10 stroke];}

1-2), use in common methods, need canvas. With Cashapelayer.

Note: 1, set the line width, color, fill, etc., are completed by Cashapelayer, Uibezierpath only complete the path of painting.

2, the size of the Cashapelayer, can be set to screen the size of screens. BOUNDS. Uibezierpath after drawing the line, automatic trimming, if not closed, will automatically connect the starting point, the end point clipping.

    

Here is the code in the learning process

-(void) drawtest{//Rectangle CGRect rect1 = {20, 20, 50, 50};        Uibezierpath *path1 = [Uibezierpath Bezierpathwithrect:rect1];    Cashapelayer *shapelayer1 = [[Cashapelayer alloc]init];    Shapelayer1.position = self.layer.position;    Shapelayer1.bounds = Self.layer.bounds; Shapelayer1.path = path1.    Cgpath; Shapelayer1.fillcolor = [Uicolor Graycolor].    Cgcolor;    [Self.layer Addsublayer:shapelayer1];    Inscribed Circle CGRect rect2 = {100, 20, 50, 50};        Uibezierpath *path2 = [Uibezierpath bezierpathwithovalinrect:rect2];    Cashapelayer *shapelayer2 = [[Cashapelayer alloc]init];    Shapelayer2.position = self.layer.position;    Shapelayer2.bounds = Self.layer.bounds; Shapelayer2.path = path2.    Cgpath; Shapelayer2.fillcolor = [Uicolor Bluecolor].    Cgcolor; Shapelayer2.strokecolor = [Uicolor Orangecolor].    Cgcolor;    Shapelayer2.strokestart = 0.0;    Shapelayer2.strokeend = 0.7;    Shapelayer2.linewidth = 3.0;        [Self.layer Addsublayer:shapelayer2]; Draw Line UibezierpAth *path3 = [Uibezierpath Bezierpath];    [Path3 movetopoint:cgpointmake (100, 100)];    [Path3 Addlinetopoint:cgpointmake (150, 100)];    [Path3 Addlinetopoint:cgpointmake (150, 150)];    [Path3 addlinetopoint:cgpointmake (100, 150)];    [Path3 addlinetopoint:cgpointmake (100, 100)];    [Path3 Addlinetopoint:cgpointmake (200, 125)];        [Path3 Addlinetopoint:cgpointmake (150, 150)];    Cashapelayer *shapelayer3 = [[Cashapelayer alloc]init];    Shapelayer3.position = self.layer.position;    Shapelayer3.bounds = Self.layer.bounds; Shapelayer3.path = Path3.    Cgpath; Shapelayer3.fillcolor = [Uicolor Redcolor].    Cgcolor; Shapelayer3.strokecolor = [Uicolor Orangecolor].    Cgcolor;    Shapelayer3.linewidth = 3.0;    Shapelayer3.fillrule = kcafillruleevenodd; [Self.layer Addsublayer:shapelayer3];}

IOS: Drawing

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.