Simple use of the "iOS development" quartz2d

Source: Internet
Author: User

Draw a line
    //Get the current canvasCgcontextref CTX = Uigraphicsgetcurrentcontext ();//2. Stitching graphics (path)    //Set segment widthCgcontextsetlinewidth (CTX,Ten);//Set style for end of segment headCgcontextsetlinecap (CTX, Kcglinecapround);//Set the style of the segment inflection pointCgcontextsetlinejoin (CTX, Kcglinejoinround);//Set colorCgcontextsetrgbstrokecolor (CTX,1,0,0,1);//Set a starting pointCgcontextmovetopoint (CTX,Ten,Ten);//Add a line segment to (+)Cgcontextaddlinetopoint (CTX, -, -);//Render onceCgcontextstrokepath (CTX);
Draw a triangle
    // 1.获得画布    CGContextRef ctx = UIGraphicsGetCurrentContext();      // 2.画三角形    00);    100100);    15080);    // 关闭路径(连接起点和最后一个点)    CGContextClosePath(ctx);    //设置颜色    0101);    // 3.绘制图形    CGContextStrokePath(ctx);
Draw a rectangle
   // 1.获得画布    CGContextRef ctx = UIGraphicsGetCurrentContext();    // 2.画矩形    CGContextAddRect(ctx, CGRectMake(1010150100));    // set : 同时设置为实心和空心颜色    // setStroke : 设置空心颜色    // setFill : 设置实心颜色    set];//    CGContextSetRGBFillColor(ctx, 0, 0, 1, 1);    // 3.绘制图形    CGContextFillPath(ctx);
Draw a Circle
  // 1.获得画布    CGContextRef ctx = UIGraphicsGetCurrentContext();     // 2.画圆    CGContextAddEllipseInRect(ctx, CGRectMake(5010100100));      10);    // 3.显示所绘制的东西    CGContextStrokePath(ctx);
Drawing arcs
// 1.获得画布    CGContextRef ctx = UIGraphicsGetCurrentContext();    // 2.画圆弧    // x\y : 圆心    // radius : 半径    // startAngle : 开始角度    // endAngle : 结束角度    // clockwise : 圆弧的伸展方向(0:顺时针, 1:逆时针)    100100500);    // 3.显示所绘制的东西    CGContextFillPath(ctx);
Painting pictures
UIImage *image = [UIImage imageNamed:@"me"];    // 2.画图片//    [image drawAtPoint:CGPointMake(50, 50)];//    [image drawInRect:CGRectMake(0, 0, 150, 150)];    [image drawAsPatternInRect:CGRectMake(00200200)];
Draw a String
   //1. Get CanvasCgcontextref CTX = Uigraphicsgetcurrentcontext ();//2. Draw a rectangle    CGRectCuberect = CGRectMake ( -, -, -, -); Cgcontextaddrect (CTX, cuberect);//3. Show what you are drawingCgcontextfillpath (CTX);//4. Drawing Text    NSString*STR = @"haha good morning hello hi Hi hi";//[str drawatpoint:cgpointzero withattributes:nil];    nsmutabledictionary*attrs = [nsmutabledictionaryDictionary];//nsforegroundcolorattributename: Text color    ///nsfontattributename: FontAttrs[nsforegroundcolorattributename] = [UicolorRedcolor]; Attrs[nsfontattributename] = [UifontSystemfontofsize: -]; [str drawinrect:cuberect withattributes:attrs];

Simple use of the "iOS development" quartz2d

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.